JSONata Selectors

JSONata Selectors Introduction

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 '`'

JSON Document for Example Selectors

This sample JSON document is used by the selector examples:

{
  "Value": 23.5,
  "Units": "Volts",
  "PreviousValues": [ 23.4, 23.2, 23.3, 23.4 ]
}

Example Selectors

JSONataResult
$ {
  "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

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.

Example array selectors:

JSONataResult
PreviousValues[0] 23.4
PreviousValues[3] 23.6
PreviousValues[-1] 23.6
PreviousValues[-4] 23.4

Further Information

Fernhill SCADA JSONata

To learn more about the supported features of JSONata in Fernhill SCADA.

Glossary

For the meaning of terms used in Fernhill SCADA.