Skip to content
JSON

JSONPath

Query expressions for locating nodes.

By EZ4Code Team
jsonpathquery

Code

// Document:
{ "store": { "book": [
  { "category": "ref", "author": "Nigel Rees", "price": 8.95 },
  { "category": "fic", "author": "Evelyn Waugh", "price": 12.99 }
] } }

// JSONPath queries:
$.store.book[*].author        // all authors
$.store..price                // all prices (recursive descent)
$..book[?(@.price < 10)]      // books cheaper than 10
$..book[-1]                   // last book
$.store.*                     // all members of store

Explanation

JSONPath is a query language that navigates JSON using dot and bracket notation similar to XPath for XML. The recursive descent operator .. searches at any depth, and filter expressions [?(@.field op value)] select nodes by predicate. Implementations vary, so check engine support for filters and script expressions.

More JSON Snippets