JsonField
The JsonField function is used to extract the value of an element within a data structure in JSON format.
Definition
JsonField(texto, elemento)Parameters
| Name | Description | Data type |
|---|---|---|
| texto | The first parameter contains the text, in JSON format, that contains the data to be extracted. | string |
| elemento | The second parameter identifies what to extract from the structure provided in the first parameter. This parameter uses JsonPath format, whose structure can be consulted here. An online evaluator for testing JsonPath expressions can also be accessed here. | string |
Example
The following example shows the use of the JsonField function to extract the "loginCount" field from a JSON structure:
JSON:
{
"firstName":"Thomas",
"lastName":"Brown",
"loginCount":4,
"devices":[
{
"name":"Cold chamber",
"type":"Temperature sensor"
},
{
"name":"Cold room door",
"type":"Door sensor"
}
]
}Get the value of the "loginCount" field
Assuming the JSON text shown in the previous section is loaded in a variable named "Json", to get the value of the "loginCount" field, use the following expression:
JsonField(Json, '$.loginCount')The result is 4 (numeric value).
Get the value of the "name" field of the second device
Assuming the JSON text shown in the previous section is loaded in a variable named "Json", to get the value of the "name" field of the second device, use the following expression:
JsonField(Json, '$.devices[1].name')The result is "Cold room door" (string).
More information
For more information about JSON structured data, consult this page.
For more information about the usage possibilities of the function's second parameter (JsonPath), review the following page https://goessner.net/articles/JsonPath/index.html#e2, or use the following online evaluator: https://jsonpath.com/