json-logic-java icon indicating copy to clipboard operation
json-logic-java copied to clipboard

objects must have exactly 1 key defined

Open 0019 opened this issue 3 years ago • 3 comments

I encountered this exception when trying to let JsonLogic return a two-keyed object:

{ "resultType": "statistics", "resultValue": 2 }

Is there any method to return Json object as result? Thanks.

0019 avatar Aug 12 '22 07:08 0019

I'm seeing the same issue and it makes the Java implementation incompatible with the javascript one. For instance, the following rule will compute fine in JS but will fail in Java. { "if": [ { "==": [ 2, 2 ] }, { "key_1": 0, "key_2": 0 }, { "key_1": null, "key_2": null } ] }

gdetoni avatar Jan 29 '23 17:01 gdetoni

As a workaround, can you treat your data as a string instead?

For example,

{
  "if": [
    {"==": [2, 2]},
    "{\"key\": \"value1\"}",
    "{\"key\": \"value2\"}"
  ]
}

jamsesso avatar Aug 27 '23 22:08 jamsesso

I saw a similar result trying to evaluate this rule:

{"and":[{"<":[5,10]},{">":[20,10]},{"==":["ON","ON"]},{">":[43200,36000]},{"<":[43200,68400]}],"or":[{">":[40,10]},{"==":["ON","ON"]}]}

It seems to work fine on the rule evaluator though

cliffamzn avatar Nov 29 '23 01:11 cliffamzn