IBM / JSONata4Java

Open Source Java version of JSONata
Apache License 2.0
88 stars 36 forks source link

$map function is throwing exception when an array has only one element #162

Open pradeepcheers opened 3 years ago

pradeepcheers commented 3 years ago

There seem like a bug in the $map function. when I try to run this expression (https://try.jsonata.org/vga_ZLC4c) on jsonata console it works fine but not in Jsonata4Java library.

wnm3 commented 3 years ago

I tried this with the current code and it seemed to work using the dataobject_9.json that I'll check in today. You can test this with the Tester application by passing the filename as an argument:

image

image

Ensure you are using the latest version: https://search.maven.org/artifact/com.ibm.jsonata4java/JSONata4Java/1.5.8/jar

Attempting to load JSON from file: dataobject_9.json
Using json:
{
  "subscriptions" : [ {
    "entitlementIds" : [ "30a2aad62" ]
  } ]
}
Enter jsonata expression (or q to quit):
subscriptions.entitlements != null
false
Enter jsonata expression (or q to quit):
subscriptions.entitlementIds != null
true
Enter jsonata expression (or q to quit):
{ "ProductEntitlements": subscriptions.entitlementIds != null ? [ $map(subscriptions.entitlementIds, function($string) { { "EntitlementId" : $string } })] : [] }
{
  "ProductEntitlements" : [ {
    "EntitlementId" : "30a2aad62"
  } ]
}