Xbasic
json_filter Function
Syntax
C result = json_filter(json as C[, propertyNames as C [, exclude as L ]] )
Arguments
- jsonCharacter
input string of JSON data
- propertyNamesCharacter
comma delimited list of the property names in the JSON string that you want to filter.
- excludeLogical
.t. or .f. - default .f. - if exclude = .t. the specified property Names are excluded from the JSON string
Description
The json_filter() Function - Extracts or omits certain properties from a JSON string. NOTE: Conceptually, this function is similar to the filter_string() function, except that it operates on JSON strings.
Example
'extract object with a single field dim json as c json = <<%txt% { "one" : 1 , "two" : "TWO" , "three" : [ 1 ,2 ,3 ] } %txt% ? json_filter(json,"one") = { "one" : 1} ? json_filter(json,"two") = { "two" : "TWO"} ? json_filter(json,"three") = { "three" : [ 1 ,2 ,3 ]} 'exclude a single field ? json_filter(json,"one",.t.) = { "two" : "TWO" , "three" : [ 1 ,2 ,3 ]} ? json_filter(json,"two",.t.) = { "one" : 1 , "three" : [ 1 ,2 ,3 ]} ? json_filter(json,"three",.t.) = { "one" : 1 , "two" : "TWO"} 'include multiple (comma separated) fields ? json_filter(json,"one,two") = { "one" : 1 , "two" : "TWO"} ? json_filter(json,"one,three") = { "one" : 1 , "three" : [ 1 ,2 ,3 ]}
See Also