I have a json as below. I want to select list reference of item which has method is "method A". But I cannot query with operator == (with Jayway JSONPath evaluation)
$.items[*].[?(@.methods[*].name == 'method A')].reference
But when I replace operator as contains, the jsonpath works.
$.items[*].[?(@.methods[*].name contains 'method A')].reference
I don't know why operator == does not work. Could anyone help me explain the reason? JSON:
{
"name": "List codes",
"items": [
{
"name": "Cash",
"reference": "CA",
"methods": [
{
"name": "method A",
"id": "3543"
},
{
"name": "method B",
"id": "3544"
}
]
},
{
"name": "Debt",
"reference": "DE",
"methods": [
{
"name": "method C",
"id": "3545"
},
{
"name": "method B",
"id": "3544"
}
]
},
{
"name": "Property",
"reference": "PR",
"methods": [
{
"name": "method C",
"id": "3545"
},
{
"name": "method A",
"id": "3543"
}
]
}
]
}
@.methods[*].name
will yield multiple results resulting into an array. You cannot use==
to compare list of values with a string.if you need to use
==
operator then you have to use the index along with||