Hi!
I am trying to filter a JSON array to select objects that match a specific attribute and possess a specific key.
In standard JSONPath (RFC 9535), I can achieve this using the existence check syntax ?(@..key). Here is an example dataset
[
{
"id": "room1",
"type": "HotelRoom",
"hasLocation": {
"type": "Relationship",
"value": "fiware_hotel",
"metadata": {}
},
"name": {
"type": "Text",
"value": "fiware_room_base_1_v2",
"metadata": {}
},
"temperature": {
"type": "Number",
"value": 0.0,
"metadata": {}
}
},
{
"id": "room2",
"type": "HotelRoom",
"hasLocation": {
"type": "Relationship",
"value": "fiware_hotel",
"metadata": {}
},
"name": {
"type": "Text",
"value": "fiware_room_base_1_v2",
"metadata": {}
},
"co2": {
"type": "Number",
"value": 0,
"metadata": {}
}
}
]
In this case, I want to select the room2, which has the key co2. I can use $[?(@.type == "HotelRoom" && @.co2)] to achieve it. You can test it here.
However, since this library uses a specific expressions for filtering, I am struggling to find the equivalent syntax to check if a key exists within the current object. I have tried $[?(@.type == "HotelRoom" and @.co2)], but it does not work. Could you give me any suggestion or maybe this is a not supported feature?
Thanks!
Hi!
I am trying to filter a JSON array to select objects that match a specific attribute and possess a specific key.
In standard JSONPath (RFC 9535), I can achieve this using the existence check syntax ?(@..key). Here is an example dataset
[ { "id": "room1", "type": "HotelRoom", "hasLocation": { "type": "Relationship", "value": "fiware_hotel", "metadata": {} }, "name": { "type": "Text", "value": "fiware_room_base_1_v2", "metadata": {} }, "temperature": { "type": "Number", "value": 0.0, "metadata": {} } }, { "id": "room2", "type": "HotelRoom", "hasLocation": { "type": "Relationship", "value": "fiware_hotel", "metadata": {} }, "name": { "type": "Text", "value": "fiware_room_base_1_v2", "metadata": {} }, "co2": { "type": "Number", "value": 0, "metadata": {} } } ]In this case, I want to select the
room2, which has the keyco2. I can use$[?(@.type == "HotelRoom" && @.co2)]to achieve it. You can test it here.However, since this library uses a specific expressions for filtering, I am struggling to find the equivalent syntax to check if a key exists within the current object. I have tried
$[?(@.type == "HotelRoom" and @.co2)], but it does not work. Could you give me any suggestion or maybe this is a not supported feature?Thanks!