A JSONata selector extracts a value from a JSON document. The syntax of a JSONata selector is:
json-selector ::=
root-selector { field-selector | array-selector }
root-selector ::=
'$' | field-name
field-selector ::=
'.' field-name
array-selector ::=
'[' jsonata-expr ']'
field-name ::=
identifier | '`' character-sequence '`'
This sample JSON document is used by the selector examples:
{
"Value": 23.5,
"Units": "Volts",
"PreviousValues": [ 23.4, 23.2, 23.3, 23.4 ]
}
JSONata | Result |
---|---|
$ |
{ "Value": 23.5, "Units": "Volts", "PreviousValues": [ 23.4, 23.2, 23.3, 23.4 ] } |
Value | 23.5 |
Units | "Volts" |
PreviousValues | [ 23.4, 23.2, 23.3, 23.6 ] |
PreviousValues[0] | 23.4 |
Array indexes are zero based. An index of 0 selects the first array element, an array index of 1 selects the second element, and so on.
Negative array indexes select values from the end of the array. An index of -1 selects the last element of the array, an array index of -2 selects the last but one element, and so on.
Example array selectors:
JSONata | Result |
---|---|
PreviousValues[0] | 23.4 |
PreviousValues[3] | 23.6 |
PreviousValues[-1] | 23.6 |
PreviousValues[-4] | 23.4 |
To learn more about the supported features of JSONata in Fernhill SCADA.
For definitions of the terms used in Fernhill SCADA.