Closed
Description
I'm trying to convert an array of API responce to an object with JSONata.
in many cases it works very well.
(JSONata is very powerful)
However, I get an error when I convert an empty array in JSONata 1.8.5.
(in 1.7.0 work as expected)
Key in object structure must evaluate to a string; got: undefined
steps to reproduce
I tried it with JSONata Exerciser.
array to object
It works in the following cases.
https://try.jsonata.org/uvEJnSWm-
jsonata: $${id:{"label":label,"value":value}}
json:
[
{
"id": "abc",
"label": "ABC",
"value": 123
},
{
"id": "def",
"label": "DEF",
"value": 321
}
]
result:
{
"abc": {
"label": "ABC",
"value": 123
},
"def": {
"label": "DEF",
"value": 321
}
}
empty array
An error occurred when json was an empty array.
https://try.jsonata.org/r9UY9cPmx
(in 1.7.0 work as expected)
json:
[]
result (1.8.5):
Key in object structure must evaluate to a string; got: undefined
result (1.7.0):
{}
workaround
The following query works even with an empty array
$count($$) > 0 ? $${id:{"label":label,"value":value}} : {}
Metadata
Metadata
Assignees
Labels
No labels