[] On parent makes arrays on subitems also
ZeroWiggliness opened this issue · 1 comments
Using [] to force a single item to an array also puts sub items into an array. This differs in fuctionality to the JSONata exerciser and thus not giving us the output we expect:
I simplified our problem:
Jsonata:
$.( { "items": orderItems.{ "itemId": itemId, "quantity": quantity.value, "code": quantity.unit }[] } )
Input:
{ "orderItems": [ { "itemId": "3fa85f64-5717-4562-b3fc-21234f66afa6", "quantity": { "value": 2, "unit": "EA" } }, { "itemId": "3fa85f64-5717-4562-b3fc-21235f66afa6", "quantity": { "value": 2, "unit": "EA" } } ] }
Expected Output:
{ "items": [ { "itemId": "3fa85f64-5717-4562-b3fc-21234f66afa6", "quantity": 2, "code": "EA" }, { "itemId": "3fa85f64-5717-4562-b3fc-21235f66afa6", "quantity": 2, "code": "EA" } ] }
Actual output:
{ "items" : [ { "itemId" : "3fa85f64-5717-4562-b3fc-21234f66afa6", "quantity" : [ 2 ], "code" : [ "EA" ] }, { "itemId" : "3fa85f64-5717-4562-b3fc-21235f66afa6", "quantity" : [ 2 ], "code" : [ "EA" ] } ] }
This is using Camel JSONata which is using 2.4.5 of this library for reference
Additional, changing to use append:
$.( { "items": $append([], orderItems.{ "itemId": itemId, "quantity": quantity.value, "code": quantity.unit }) } )
Causes it to give the desired output.