0

I am having a doubt where while giving a JSON Path, I am getting following output.

Input JSON :-

{
    "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
}
                    

JSON Path Expression : $.*

My understanding is this should give every element of the JSON from root. Using this evaluator https://jsonpath.herokuapp.com/

I got this response output JSON :

[
   {
      "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
      }
   },
   10
]

I have following Questions -

  1. What does this expression mean is my understanding correct ?
  2. Why was key expensive removed from the response , we can see only value 10 in the response.
  3. In my real time use case, when user is providing the above expression the program goes into Index Out of Bound, is it because if my actual json is having too many array elements and when we ask for $.* it gives all possible solution ? how do I handle such case, is there any simpler way.
agaonsindhe
  • 447
  • 1
  • 5
  • 13
  • 1
    Use the option **Normalized path expressions** in https://jsonpath.herokuapp.com/. This will give you an idea of why the output is like that. – Akshay G Oct 07 '22 at 08:20
  • `$..*` gives all possible expressions. You need to use two dots for Deep scan – Akshay G Oct 07 '22 at 08:21

0 Answers0