|
<< Click to Display Table of Contents >>
JSON Path Tags |
Use an I/O Tag or a Block Tag to read a value directly by its path in JSON format of the response to a request, without declaring a template. The path is informed in the Item parameter with a $ (dollar sign) prefix, according to the next table.
Item |
<Route Alias>;$<Path>[@<Timestamp path>[:<Format>]] |
N1 or B1 |
Not used, leave it in 0 (zero) |
N2 or B2 |
Not used, leave it in 0 (zero) |
N3 or B3 |
Not used, leave it in 0 (zero) |
N4 or B4 |
Not used, leave it in 0 (zero) |
JSON Path Tags coexist with Tags that use a template on the same route and in the same request. They are recommended for reading a few values from large responses and for responses with dynamic keys, such as dates or identifiers that cannot be mapped by a template. There must be no spaces around the ; (semicolon) character in the Item parameter.
A request is still triggered by writing to the PLC Tag configured with the N1 parameter equal to 1 (one). When a response arrives, this Driver navigates to the informed path and delivers the value to this Tag. Use an I/O Tag for a single value and a Block Tag for lists and objects.
Elements of a path
Element |
Syntax |
Example |
Description |
|---|---|---|---|
Object key |
key |
total_30d |
Accesses the key of an object |
Nested keys |
a.b.c |
data.config.max |
Navigates through objects inside objects |
Array index |
[n] or [-n] |
data[0], data[-1] |
nth element of an array. A negative index counts from the end of an array |
Positional index in an object |
[n] or [-n] |
daily_rain[-1] |
nth key of an object, in the order of a document |
Wildcard |
[*] |
data[*].level |
All elements of an array. This Tag receives a list with the rest of the path applied to each element |
Date macro |
{TODAY}, {TODAY-n}, or {TODAY+n} |
daily_rain.{TODAY-1} |
Current local date, minus or plus n days, used as a key. The default format is %Y-%m-%d. This macro is expanded at every request |
Date macro with format |
{TODAY-n:format} |
{TODAY-1:%d/%m/%Y} |
Date format with the same options as the TS_TEXT keyword |
Quoted key |
'key' or "key" |
'config.v2' |
Addresses keys containing periods, brackets, or braces |
Data timestamp |
@path[:format] |
level@datetime |
Stamps a value with a timestamp read from the JSON format itself, as described next |
The path after the @ (at) character is resolved from the root of a response and accepts the same syntax as the path of a value, except for the * (asterisk or wildcard) character. When the path of a value points to an array of objects, or repeat mode, the path of a timestamp is resolved relative to each element, stamping each reading with the time of its own sample.
If the pointed value is a number, it is interpreted as a timestamp in UNIX format, in seconds. If it is a text, it is converted using the format informed after the colon character, whose default is %Y-%m-%dT%H:%M:%S, with the same options as the TS_TEXT keyword, including the default %f for milliseconds and %+ for the time zone.
A failure in a timestamp does not prevent a value from being delivered. This error is recorded in the log file of this Driver and the value is delivered with the default timestamp, which is the reading time.
Conversion of a value to a Tag
Value in JSON Format |
Result in a Tag |
|---|---|
Number or text |
Value of a Tag. Texts that represent numbers follow the rule described in section Conversion of Values Received as Text |
Object |
Block Tag with the values of the keys, in the order of a document. Nested objects are converted to sub-lists |
Array of numbers or texts |
Block Tag with a list of values |
Array of objects |
One reading per element, each reading with the values of the keys of an object, equivalent to the Repeat_E3VAL keyword |
null |
Empty value with bad quality |
The next examples use the demand route, whose response, in summary, is the following:
{
"daily_rain": {
"2026-06-12": 0.4,
...
"2026-07-22": 15.4
},
"data": [
{
"rain_15min": 70.0,
"level": 2.64,
"datetime_brt": "2026-07-12T14:30:00-03:00"
},
...
{
"rain_15min": 0.0,
"level": 2.57,
"datetime_brt": "2026-07-22T13:15:00-03:00"
}
],
"station": "BE70C78A",
"total_30d": 9359.4
}
Examples of Items and results
Item |
Result |
|---|---|
demand;$total_30d |
9359.4 |
demand;$station |
BE70C78A |
demand;$data[-1].level |
2.57 (level of the last sample) |
demand;$data[0].level |
2.64 (level of the first sample) |
demand;$daily_rain.{TODAY} |
15.4 (key 2026-07-22, considering the current date as 07/22/2026) |
demand;$daily_rain[-1] |
15.4 (value of the last key of an object) |
demand;$data[-1].level@data[-1].datetime_brt:%Y-%m-%dT%H:%M:%S%+ |
2.57 with timestamp 07/22/2026 13:15:00, read from the sample itself |
demand;$data[*].level |
Block Tag with the list of all levels |
demand;$daily_rain |
Block Tag with the daily values, in the order of this document |
demand;$data[0] |
Block Tag with the fields of the first record, in the order of this document |
demand;$data |
One reading per record, each one with the fields of an object, as in the Repeat_E3VAL keyword |
demand;$data@datetime_brt:%Y-%m-%dT%H:%M:%S%+ |
Same as the previous item, with each reading stamped with the timestamp of its own sample |
demand;$ |
The whole response as a nested Block Tag, that is, daily_rain, data, station, and total_30d |
NOTE |
JSON Path Tags are read-only. Writing to these Tags is rejected and sending data still requires a template. A path that does not exist in a response is recorded in the log file and does not prevent updating other Tags from the same request. With the * (asterisk or wildcard) character, the elements in which the rest of the path does not exist are ignored. A malformed Item parameter is rejected when creating this Tag. The date macro uses the local clock of the computer in which this Driver executes. |