I am just trying JsonPath. It's great but I have a problem with a special case. I searched here but could not find a solution.
So, my JSON file is below:
[
{
"id": 1,
"images": [
{ "id": 1,"url": "http://url1.jpg" },
{ "id": 2,"url": "http://url2.jpg" }
]
},
{
"id": 2,
"images": [
{ "id": 1,"url": "http://url3.jpg" },
{ "id": 2,"url": "http://url4.jpg" }
]
},
{
"id": 3,
"images": [
{ "id": 1,"url": "http://url5.jpg" },
{ "id": 2,"url": "http://url6.jpg" }
]
}
]
With this expression $.[?(@.id=='2')]
, the result is
[
{
"id": 2,
"images": [
{
"id": 1,
"url": "http://url3.jpg"
},
{
"id": 2,
"url": "http://url4.jpg"
}
]
},
{
"id": 2,
"url": "http://url2.jpg"
},
{
"id": 2,
"url": "http://url4.jpg"
},
{
"id": 2,
"url": "http://url6.jpg"
}
]
But I need to restrict my query result to one level without the children. The last 3 elements are not necessary. I need only the first element.
{
"id": 2,
"images": [
{
"id": 1,
"url": "http://url3.jpg"
},
{
"id": 2,
"url": "http://url4.jpg"
}
]
}