Extract multiple values from a JSON using JSONPath

Viewed 94

I'd like to extract, using JSONPath, some values from a JSON like this one

{
"key": "value",
"array": [
    {
        "key": 1,
        "item": "a",
        "cod": 123
    },
    {
        "key": 2,
        "item":"b",
        "cod": 345
    },
    {
        "key": 3,
        "item": "c",
        "cod": 126
    }
]

}

I'd like to extract "key" AND "cod" values ....

I'm trying to use this JSONPath filter $.array[*]['key','item'] but it doesn't work.

enter image description here

Is it possible? Any suggestions? Thank you in advance!

2 Answers

this works for me

$.array[*].key,item

you just selected a wrong website , try this https://jsonpath.com/ for example or better create java script code. You jsonPath is working here

console.log(jsonPath(arr,("$.array[*]['key','item']")));

output

[
  1,
  "a",
  2,
  "b",
  3,
  "c"
]

Starting from the @Serge reply (thanks ...), I've retried using https://www.jsonquerytool.com/ that I've used in my initial test BUT changing the transformation used (JSONPath Plus (4.0.0) in this case, and its' working now

enter image description here

Related