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 storeExplanation
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
Data Types
The seven JSON value types.
Nested Objects
Objects within objects for hierarchical data.
Arrays
Lists of mixed and homogeneous values.
Schema Validation
Validate structure with JSON Schema.
Merge Patch (RFC 7386)
Partially update JSON documents.
JSON Pointer (RFC 6901)
Address a specific value by path.