Given the following JSON structure, I want to be able to find the entry in the $.data
array that contains an item with a specific itemId
.
{
"data": [
{
"id": "1",
"items": [{"itemId": "item1"}]
},
{
"id": "2",
"items": [{"itemId": "item2"}]
}
]
}
Let's say I'm looking for the entry with an itemId == "item2"
- in which case I want to extract the full object:
{
"id": "2",
"items": [{"itemId": "item2"}]
}
I've attempted nesting $()
filters, but to no avail:
$.data[?@.items[?(@.itemId == "item2")])]
$.data[?("item2" in @.items[*].itemId)]
$.data[?(@.items[*].itemId contains "item2")]
I can easily find the "item" object itself, through $.data[*].items[?(@.itemId == "item2")]
, but I'd like to actually retrieve its parent object! Is this even possible with JSONPath?