2

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 2

4

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"
]
Sign up to request clarification or add additional context in comments.

4 Comments

$.array[*]['key','item'] This is not working at jsonpath.com
@ArtBindu Thanks, you are right. it only works in the code
I saw a different issue in the different compilers: jsonpath.com. $.array[*].key,item is not working here. See the same observation at site24x7.com/tools/json-path-evaluator.html Also, seeing different types of compilers send us different types of answers. So, can you suggest me best compiler to understand JSON path coding deeply.
@ArtBindu There are different jsonPath libraries. And they work different. I don't know what OP uses, I am not sure that he knows it too.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.