Browse the docs

jsonPath

Returns the value at a path inside JSON.

Details #

jsonPath(json, path) takes exactly two arguments.

json is a record or list, or text holding JSON, which is parsed first. path reaches into it: $.user.name or user.name for keys, [0] for list items (negative counts from the end, [-1] is the last), and ['key with spaces'] for awkward keys. The leading $ is optional.

What comes back is whatever sits at the path: text, number, true/false, list or record. A path that leads nowhere gives nothing (null).

Parameters #

Takes 2 arguments. {{ jsonPath(text, b) }}

Examples #

jsonPath(data, "$.user.tags[1]")
→ engines
Sample variableValue
data{"user": {"name": "Ada", "tags": ["math", "engines"]}}
jsonPath(text, "items[-1].id")
→ 7
Sample variableValue
text{"items": [{"id": 1}, {"id": 7}]}

Gotchas #

  • Text that isn't valid JSON is an error: jsonPath() got text that isn't valid JSON.

  • A missing key or an index out of range is not an error, it is null. jsonValue gives empty text instead.