I have the following JSON and I need to get the plain name value using JSONPath:
{
"data": [
{
"code": "ABC",
"metadata":
{
"id": "111",
"data": "2020"
}
},
{
"code": "123",
"metadata":
{
"id": "222",
"data": "2018"
}
},
{
"code": "XYZ",
"metadata":
{
"id": "555",
"data": "2018"
}
}
]
}
I want to get the value of a variable "code" via "id".
Expression that I used is $.data[?(@.metadata.id == '222')].code
to get the "code"="123". But it doesn't work.
What am I doing wrong?