IBM / JSONata4Java

Open Source Java version of JSONata
Apache License 2.0
91 stars 38 forks source link

[] On parent makes arrays on subitems also #290

Open ZeroWiggliness opened 10 months ago

ZeroWiggliness commented 10 months ago

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

ZeroWiggliness commented 10 months ago

Additional, changing to use append:

$.( { "items": $append([], orderItems.{ "itemId": itemId, "quantity": quantity.value, "code": quantity.unit }) } )

Causes it to give the desired output.