Let's consider the following input:
{
"equipments": [
{
"type": "Type A",
"name": "Name A"
},
{
"type": "Type A",
"name": "Name A2"
},
{
"type": "Type B",
"name": "Name B"
}
],
"data": [
{
"id": "0001",
"equipmentName": "Name A"
},
{
"id": "0001",
"equipmentName": "Name A2",
"value": 1
},
{
"id": "0001",
"equipmentName": "Name B",
"value": 2
},
{
"id": "0002",
"equipmentName": "Name A",
"value": 3
},
{
"id": "0003",
"equipmentName": "Name A2",
"value": 3
}
]
}
and the following Jsonata:
equipments@$equipments.data
[$equipments.type = "Type A" and $equipments.name = equipmentName] {
id: {
"equipmentNames": equipmentName[]
}
}
which correctly results in
{
"0001": {
"equipmentNames": [
"Name A",
"Name A2"
]
},
"0002": {
"equipmentNames": [
"Name A"
]
},
"0003": {
"equipmentNames": [
"Name A2"
]
}
}
Now the issue is, if:
- in the input
equipments is empty or does not exist
- or
data is empty or does not exist
- or the filter
[ ... ] (e.g. by changing "Type A" into "Type C") returns an empty result
then the following error is thrown:
can't access property "@", c is undefined
It looks like a bug since the error message is not clear about what I did wrong.
I could add a . after the filter but this changes the result and messes up the grouping:
equipments@$equipments.data
[$equipments.type = "Type A" and $equipments.name = equipmentName]. {
id: {
"equipmentNames": equipmentName[]
}
}
Let's consider the following input:
{ "equipments": [ { "type": "Type A", "name": "Name A" }, { "type": "Type A", "name": "Name A2" }, { "type": "Type B", "name": "Name B" } ], "data": [ { "id": "0001", "equipmentName": "Name A" }, { "id": "0001", "equipmentName": "Name A2", "value": 1 }, { "id": "0001", "equipmentName": "Name B", "value": 2 }, { "id": "0002", "equipmentName": "Name A", "value": 3 }, { "id": "0003", "equipmentName": "Name A2", "value": 3 } ] }and the following Jsonata:
which correctly results in
{ "0001": { "equipmentNames": [ "Name A", "Name A2" ] }, "0002": { "equipmentNames": [ "Name A" ] }, "0003": { "equipmentNames": [ "Name A2" ] } }Now the issue is, if:
equipmentsis empty or does not existdatais empty or does not exist[ ... ](e.g. by changing"Type A"into"Type C") returns an empty resultthen the following error is thrown:
It looks like a bug since the error message is not clear about what I did wrong.
I could add a
.after the filter but this changes the result and messes up the grouping: