evaluate JSON data

JsonPath: Is the way to reach a particular node in the JSON data. It is similar to XPath and starts from the root node. There are numerous online tools that can be used to evaluate the structure and analyse the JSON data using JsonPath.

One such is http://jsonpath.com/
Given we have Json data as below:

{
    "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
        }
    },
    "expensive": 10
}
 
Now we want to evaluate this.
Step 1: Paste the json in the left hand panel of the online tool  
Step 2: Also paste the same in the left hand panel here.
        You should get the output as below:
This basically structures the json into more readable format.You can see that
the json data has 2 objects store and expensive. store contains 2 child objects
out which one is book which is an array of 4 elements and the other is bicycle with
2 elements. 
Now in the tool
> $.store will yield data for the store object with all the children and subnodes.

> $.store.book[1] will yield data for the 2nd book in the json data

 > $.store.book[1].author yields the author name of the 2nd book
>  $.store.book[1,2] yields the 2nd and the 3rd book
>  $.store.book[?(@.price>10)]  all the books with price  >10

>  $.store.book.length
 

Comments

Popular Posts