Search code examples
jsonpathjson-path-expression

I want to know how to get Test1 value using Jsonpath


I want to know the value of "Test1" whose "createdTs" value is greater than or equal to 444.

[
   {
"raw" : {
      "Test1":"Apple",
      "Test2":{
            "createdTs": 333,
            "langCode": "ko"
        }
    }
},
    {
"raw" : {
      "Test1":"Tomato",
      "Test2":{
            "createdTs": 555,
            "langCode": "ko"
        }
    }
}
]

Even if I call Jsonpath as shown below, it does not work.

$[?(@.['Test2'].createdTs > 444)]

The result I want is like below.

"raw" : {
      "Test1":"Tomato",
      "Test2":{
            "createdTs": 555,
            "langCode": "ko"
        }
    }


Solution

  • To access the path you need to specify all the attributes from parent node till the child node.

    $[?(@.raw.Test2.createdTs > 444)]

    Kindly go through the documentation completly to learn and understand how jayway jsonpath works. https://github.com/json-path/JsonPath#getting-started

    Online Test Tool : https://jsonpath.herokuapp.com/