JsonQuery to fetch multiple values is not working on using com.jayway.jsonpath.JsonPath jar with JAva

690 views
Skip to first unread message

Swaminathan Pasunkili

unread,
Jun 22, 2016, 3:29:15 AM6/22/16
to JsonPath
Please find the below extract from my lengthy JSON file.

{
    "key" : "value",
    "array" : [
        { "key" : 1 },
        { "key" : 2, "dictionary": {
                "a": "Apple",
                "b": "Butterfly",
                "c": "Cat",
                "d": "Dog"
            } },
        { "key" : 3 }
    ]
}

Im trying to use this query - $.array[?(@.key=2)].dictionary.a,b,c
which is not fetching any results while using the jar

But on parsing the same Json in http://www.jsonquerytool.com/ , the above JSon Query gives the below Expected result - 

[
    "Apple",
    "Butterfly",
    "Cat"
]






Warwick Hunter

unread,
Jul 12, 2016, 7:30:22 PM7/12/16
to JsonPath
You need to use == in the expression. I don't believe that you can select multiple elements with ".a,b,c".

This expression

$.array[?(@.key==2)].dictionary.a

Gives:

["Apple"]
Reply all
Reply to author
Forward
0 new messages