0
{
    "responseCode": "200",
    "data": {
        "sequence": 1,
        "used": true,
        "sensingTags": [
            {
                "code": "LED",
                "value": 1,
                "updatedOn": 1587557350251
            }
        ]
    }
}

My goal is get updatedOn value from this json using jsonPath like this

1587557350251

i thought below jsonPath will work but it extract only empty list.

$..sensingTags[?(@.code == 'LED')][0].updatedOn

And i want to know how to extract value like below

            {
                "code": "LED",
                "value": 1,
                "updatedOn": 1587557350251
            }

Not like this one.

[
   {
      "code" : "LED",
      "value" : 1,
      "updatedOn" : 1587557350251
   }
]

1 Answers1

1

As per Getting a single value from a JSON object using JSONPath, JsonPath will always return an array (or a false) at that point...

Best you can do is process it as an array of updatedOn and simply always grab the first value.

$..sensingTags[?(@.code == 'LED')].updatedOn
Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61