Extracts part of a JSON response.
string JSELECTTOKEN(Jtoken object, string to Json path)
Object | Data Type | Description |
---|---|---|
Jtoken object | String | The name of the JSON object to extract from. |
Json path | Integer | The path to the JSON object |
The JSON path will vary depending on the level the object is found, below are a few examples of how you can structure your path to extract the data.
If we take the following JSON response and imagine this is being returned in Data Sync as a single column called "MyJson":
{
'Stores': [
'Lambton Quay',
'Willis Street'
],
'Manufacturers': [
{
'Name': 'Acme Co',
'Products': [
{
'Name': 'Anvil',
'Price': 50
}
]
},
{
'Name': 'Contoso',
'Products': [
{
'Name': 'Elbow Grease',
'Price': 99.95
},
{
'Name': 'Headlight Fluid',
'Price': 4
}
]
}
]
}
We can use the following examples to extract different object as different levels.
If we wanted to extract the first store in the list we can use the following expression.
JSELECTTOKEN(MyJson, "Stores[0]")
This would return "Lambton Quay".
To get the name of the first manufacturer we can use:
JSELECTTOKEN(MyJSONColumn, "Manufacturers[0].Name")
Which would return "Acme Co".
If we want to return the name of the first product from the second manufacturer we could use:
JSELECTTOKEN(MyJSONColumn, "Manufacturers[1].Products[0].Name")
Which would return "Elbow Grease".
To return an array of all the stores you can use the below expression but it will be decorated with []
as it is an array.
JSELECTTOKEN(MyJSONColumn, "Stores")
Which will return "[ "Lambton Quay", "Willis Street"]"