Query Data With JSON Path
JSON Path is a query language to analyze, transform, and selectively extract data from JSON documents or JavaScript objects. It is similar to XPath for XML documents. In this guide we will explore how to use it in Apirios.
In case you need more information you can also check the JSONPath-Plus official documentation, the library we use internally to evaluate JSON Path expressions.
Syntax
Example JSON data:
{ "store": { "book": [ { "title": "Book A", "price": 10 }, { "title": "Book B", "price": 15 }, { "title": "Book C", "price": 8 } ] }}
Description | Query | Result |
---|---|---|
First book | $.store.book[0] | { "title": "Book A", "price": 10 } |
Last book price | $.store.book[(@.length-1)].price | 8 |
All books titles | $.store.book[*].title | ["Book A", "Book B", "Book C"] |
Books cheaper than $10 | $.store.book[?(@.price < 10)] | [{ "title": "Book C", "price": 8 }] |
All prices in the store | $.store..price | [10, 15, 8, 100] |
Usage
In Apirios, you can use JSON Path expressions in the following places:
- Node input transformation
- JSON Path node