jsonutil

package
v0.1.0-M4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: Apache-2.0, EPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONArraySubset

func JSONArraySubset(input, selector string) (string, error)

JSONArraySubset generates a new JSON array adding the field selector defined values only for each array element. Returns error if the provided JSON string is not valid JSON array.

func JSONSubset

func JSONSubset(input, selector string) (string, error)

JSONSubset generates a new JSON object adding the field selector defined values only. For JSON Arrays use the JSONArraySubset function. Returns error if the provided JSON string is not valid JSON object.

For field selector parsing to set of JSON pointers is used SelectorToJSONPointers utility. For example: 1. "attributes/model,attributes/location", would select only model and location attribute values (if present) 2. "attributes(model,location)" would select only model and location attribute values (if present) 3. "features/feature1/properties(city,street) would select from city and street values inside properties inside feature1 of features (if present) 4. "features(feature1/properties,feature1,feature2/properties/country(city,street),feature2)" would select only properties inside feature1 inside feature and city and street inside country inside properties inside feature2 inside features. Note that feature1 and feature2 inside features will not be selected.

func SelectorToJSONPointers

func SelectorToJSONPointers(selector string) ([]string, error)

SelectorToJSONPointers returns array of the JSON pointers (https://tools.ietf.org/html/rfc6901) for a given fields selector string.

Rule example:

  1. thingId,attributes/model,attributes/location and thingId,attributes(model,location), would return the same array:

[

/thingId,
/attributes/model,
/attributes/location,

] 2. features/feature1/properties(city,street), would return array: [

/features/feature1/properties/city,
/features/feature1/properties/street,

] 3. features(feature1/properties,feature1,feature2/properties/country(city,street),feature2), would return array, including only most inner paths: [

/features/feature1/properties,
/features/feature2/properties/country/city,
/features/feature2/properties/country/street,

], i.e. features/feature1 and features/feature2 are not returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL