The JsonGetValue function uses a JSONPath expression to look up the value of a specific path.
string @JsonGetValue(string objectId, string jsonPath);
Parameters
string objectId : Target JSON object ID
string key : JSONPath expression to look up the value
Return Values
Returns the value corresponding to the path on success (returns a comma-separated string if multiple values are queried)
Return an empty string on failure
Note. JSONPath Expression Examples
$.name
: The "name" attribute of the top-level object
$.address.city
: The "city" property of the nested object
$.items[0]
: the first element of the array
$.items[*]
: All array elements
$.. name
: All "name" attributes in the object tree
$.items[?( @.price>10)]
: Array element that matches the condition (element whose price is greater than
10)
Example )
//Assume the JSON string below is the current value of the
string variable jsonString
{
"person": {
"name": "John",
"age": 20
},
"items": [
"First",
"Second"
]
}
string jsonObjectId = @JsonFromString(jsonString); //Parse JSON strings
as JSON objects
// Single-value lookup
string name = @JsonGetValue(jsonObjectId, "person.name");
// Result
: John
// Array element lookup
string secondItem = @JsonGetValue(jsonObjectId, "items[1]");
// Result : Second
// Multiple element lookups
string allNames = @JsonGetValue(jsonObjectId,
"$..name");
// Result: John
Version information
Supported Version: 10.3.6.25 or later
Related Helps)
JsonTemplateReplacePlaceholder