Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[] On parent makes arrays on subitems also #290

Open
ZeroWiggliness opened this issue Nov 24, 2023 · 1 comment
Open

[] On parent makes arrays on subitems also #290

ZeroWiggliness opened this issue Nov 24, 2023 · 1 comment

Comments

@ZeroWiggliness
Copy link

ZeroWiggliness commented Nov 24, 2023

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
Copy link
Author

Additional, changing to use append:

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

Causes it to give the desired output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant