Json query syntax¶
Some nodes allow you to input a Json query, which is a string parameter for selecting what parts of a Json structure to work on. For simple queries they can usually be created by clicking on an entry in the tree view of the query editor, but more advanced queries must be entered by hand. Such queries must adhere to a specific syntax to give the correct results.
Let’s start off with a few examples:
articles[0].author
articles[:].comments[:]
users.*.fullName
The query is built out of segments where each segment is either a key, an index, a pattern, or a slice. The empty query (with no segments) matches the root of the Json structure.
Simple keys¶
A key is a simple string used to select a single entry in a dictionary.
It is written: .key
, but for simple keys at the start of the query, the
period is omitted: key
.
The key ends when a period (.
) or a left square bracket ([
) is found.
Including an asterisk (*
) in the key turns it into a
pattern. To be able to include any of these
characters in a key you need to use a
bracketed key. The key can include Unicode
characters directly in the string.
Patterns¶
Like a key but with one or more asterisks in it: .key*
. Selects the values
of all keys that match the pattern with asterisks interpreted as wildcards that
can match zero or more arbitrary characters. As an important special case, the
pattern .*
selects all entries in the dictionary.
Indices¶
An index is used to select a single entry from a list.
It is written [5]
, starting at index zero for the first entry in the list.
The index can also be negative with [-1]
denoting the last entry in the list,
[-2]
denoting the second-to-last entry, and so on.
This exactly mirrors how Python interprets indices in lists.
Slices¶
A slice is used to select multiple entries in a list.
It can be written [3:8]
for selecting entries with indices from 3 (inclusive)
to 8 (exclusive).
The slice can also contain a third part (separated by another colon) which is
interpreted as a step. As an example [3:8:2]
would select indices 3, 5,
and 7. Only positive steps are supported.
If the start is omitted ([:8]
) the slice starts from the first entry in the
list. If the end is omitted ([3:]
) the slice includes all entries until the end of the list.
As an important special case, the full slice [:]
selects all entries in the list.
This is a subset of the slice syntax in Python.
Bracketed keys¶
Bracketed keys: ["key"]
or ['key']
selects a single entry in a dictionary.
The key can include Unicode characters directly in the string. The following escape sequences are also recognized:
Escape sequence |
Meaning |
---|---|
|
Backslash (\) |
|
Single quote (‘) |
|
Double quote (“) |
|
Line Feed (U+000A) |
|
Carriage Return (U+000D) |
|
Vertical Tab, (U+000B) |
|
Unicode character with hexadecimal code point hh |
|
Unicode character with hexadecimal code point hhhh |
|
Unicode character with hexadecimal code point hhhhhhhh |
This is a subset of the escape sequences in Python strings: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals.