Json Path

JSONPath is a tool for picking specific parts from a JSON object. Think of it like XPath, but for JSON instead of XML. With JSONPath, you can easily pull out individual values, entire sections, or even lists and properties from a JSON document. Whether you have a straightforward JSON or a complex one,

JSONPath can navigate through its structure. It's a popular choice among developers because many programming languages support it, making it a go-to for handling JSON data.

Sample:

{
"store": {
"book": [
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"price": 22.99
},
{
"category": "science",
"author": "Carl Sagan",
"title": "Cosmos",
"price": 14.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}

Here are some JSONPath expressions and their results:

  1. $..book
    Gets all books from the store.

  2. $.store.book[0]
    Gets the first book from the list.

  3. $.store.bicycle.color
    Returns the color of the bicycle, which is "red".

  4. $..book[(@.length-1)]
    Retrieves the last book from the list.

  5. $..book[-1:]
    Also retrieves the last book in the list (alternative syntax).

These are just some basic examples. JSONPath provides a rich set of query options, enabling complex queries and navigation depending on the structure and requirements.