Using JSONPath In Sanbox

How to use JSONPath

It's important to learn JSONPath to work efficiently in Sanbox. JSONPath lends itself to XPath, a query language used to extract data from XML documents. JSONPath expressions start with the $ character denoting the outer level object, but can be omitted. For example $ and are the same.

JSONPath expressions can use the dot-notation:


Or the bracket-notation:


Syntax Elements




The root object or array.


Selects the specified property in a parent object.


Selects the specified property in a parent object. Be sure to put single quotes around the property name.

Tip: Use this notation if the property name contains special characters such as spaces, or begins with a character other than A..Za..z_.


Selects the n-th element from an array. Indexes are 0-based.


Selects array elements with the specified indexes. Returns a list.

Recursive descent: Searches for the specified property name recursively and returns an array of all values with this property name. Always returns a list, even if just one property is found.


Wildcard selects all elements in an object or an array, regardless of their names or indexes. For example, address.* means all properties of the addressobject, and book[*] means all items of the book array.

[start:end] [start:]

Selects array elements from the start index and up to, but not including, endindex. If end is omitted, selects all elements from start until the end of the array. Returns a list.


Selects the first n elements of the array. Returns a list.


Selects the last n elements of the array. Returns a list.


Filter expression. Selects all elements in an object or array that match the specified filter. Returns a list.


Script expressions can be used instead of explicit property names or indexes. An example is [(@.length-1)] which selects the last item in an array. Here, length refers to the length of the current array rather than a JSON field named length.


Used in filter expressions to refer to the current node being processed.


  • JSONPath expressions, including property names and values, are case-sensitive.

  • Unlike XPath, JSONPath does not have operations for accessing parent or sibling nodes from the given node.


Filters are logical expressions used to filter arrays. An example of a JSONPath expression with a filter is

$[?(@.price < 10)]

where @ represents the current array item or object being processed. Filters can also use $ to refer to the properties outside of the current object:

$[?(@.price < $.expensive)]

An expression that specifies just a property name, such as [?(@.isbn)], matches all items that have this property, regardless of the value.

Filters support the following operators:




Equals to. 1 and '1' are considered equal. String values must be enclosed in single quotes (not double quotes): [?(@.color=='red')].


Not equal to. String values must be enclosed in single quotes.


Greater than.


Greater than or equal to.


Less than.


Less than or equal to.


Match a JavaScript regular expression. For example, [?(@.description =~ /cat.*/i)] matches items whose description starts with cat (case-insensitive).


Use to negate a filter: [?([email protected])] matches items that do not have the isbn property.


Logical AND, used to combine multiple filter expressions:

[?(@.category=='fiction' && @.price < 10)]


Logical OR, used to combine multiple filter expressions:

[?(@.category=='fiction' || @.price < 10)]


For the following examples, we will use this data:

{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
"bicycle": {
"color": "red",
"price": 19.95




the authors of all books in the store


all authors


all things in store, which are some books and a red bicycle


the price of everything in the store


the third book




the last book in order


-or- $[:2]

the first two books


filter all books with isbn number


filter all books cheaper than 10


all members of JSON structure