JsonField
The JsonField function is used to extract the value of an element within a data structure in JSON format.
Definition
JsonField(texto, elemento)参数
| 名称 | 说明 | 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 此处. An online evaluator for testing JsonPath ex按下ions can also be accessed 此处. | string |
示例
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 ex按下ion:
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 ex按下ion:
JsonField(Json, '$.devices[1].name')The result is "Cold room door" (string).
更多信息
更多信息 about JSON structured data, consult this page.
更多信息 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/