jamsesso / json-logic-java

A pure Java implementation of JsonLogic without using the Nashorn JS engine
MIT License
97 stars 50 forks source link

Getting all variables from the rules for building context #34

Closed pg30 closed 1 year ago

pg30 commented 1 year ago

I need to parse the rule to find all the variables used in the rule so that I can build context with only required data. Is there a pre-defined method for that?? Also what are the possible ways for defining a variable name? Will it only be a number or a string or can it be a sub-rule in itself which can be evaluated to a variable name??

jamsesso commented 1 year ago

You can use Gson directly to do that. You can pass in a string (your json-logic expression) and then use the Gson API to list all of the keys on the object. Search the object recursively to find objects that have exactly one key with the value "var".

As for the second part of the question, no - variables are static.