Why does $map not output an array in case the input array is one in length?

812 Views Asked by At

Please check this - https://try.jsonata.org/0L_oYffzT

Here the output of the $map function is not an array.

whereas https://try.jsonata.org/Rf8UI_TMy seems to work fine when the input array is more than 1 in length.

1

There are 1 best solutions below

3
On

You may use the result structure feature to accomplish this task:

var json = { "projectIds": [ 1 ] }
var result = jsonata('projectIds[].{"projectId": $}').evaluate(json);
console.log(JSON.stringify(result))
<script src="https://cdn.jsdelivr.net/npm/jsonata/jsonata.min.js"></script>

Using $map for this purpose has an open issue that point to workarounds only