JSONQuery
JSONQuery
The JSONQuery is an operator, that allows to query any value from the input JavaScript Object Notation (JSON) string using JSON Pointer syntax.
JSON Pointer can be used to specify a specific object within a JSON document. JSON Pointer uses a relatively simple string syntax to represent the path to any JSON element. The JSON Pointer syntax consists of segments separated by /. Each segment can be either an object key or an array index (starting from zero).
Arguments
Name | Description |
---|---|
In | The JSON-formatted string |
Out | Value that was located from the input by the Query |
Properties
Name | Description |
---|---|
Query | Query string in the JSON Pointer syntax identifying the value to search from the input JSON. If the value can not be found, the output value is set to empty. If Query is left empty, then the input JSON value is simply copied to the output. |
Example
Let's consider this JSON document as an input for some example queries:
{ "name": "Jan", "age": 30, "address": { "city": "Oslo", "postalCode": "1001" }, "pets": [ {"name": "Fido", "type": "Dog"}, {"name": "Whiskers", "type": "Cat"} ] }
Below is a table with some JSON Pointer queries and results for this JSON:
Example Query | Value that will be found | Description |
---|---|---|
/name | Jan | Search for the name attribute |
/address/city | Oslo | Search for the city attribute within the address object |
/pets/1/name | Whiskers | Search for the second element name attribute in the pets array |
/pets | [{"name": "Fido", "type": "Dog"},{"name": "Whiskers", "type": "Cat"}] | Retrieve all elements from the pets array |
/pets/0 | {"name":"Fido","type":"Dog"} | Retrieve the first element from the pets array |
See also JSONDecode and Argument.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.