JSONata Selectors

Help Contents

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 | string-literal | '`' character-sequence '`'

JSON Document for Example Selectors

This sample JSON document is used by the selector examples:

{
    "Value": 23.5,
    "Units": "Volts",
    "Previous_Values": [ 23.4, 23.2, 23.3, 23.4 ],
    "Test Values": { "First Value": 12.5, "Second Value": 37.5 }
}

Example Selectors

JSONataResult
$ {
  "Value": 23.5,
  "Units": "Volts",
  "PreviousValues": [ 23.4, 23.2, 23.3, 23.4 ]
}
$.Value 23.5
Value 23.5
Units "Volts"
Previous_Values [ 23.4, 23.2, 23.3, 23.6 ]
Previous_Values[0] 23.4
`Test Values`.`First Value` 12.5
`Test Values`."Second Value" 37.5

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
Previous_Values[0] 23.4
Previous_Values[3] 23.6
Previous_Values[-1] 23.6
Previous_Values[-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.