I'm trying to parse a nested associative array in JMP 16 (extracted from a JSON). The basic structure of the JSON is as follows:
{
"groupOp": "&",
"rules": [
{"column": "col1", "op": "==", "value": 1},
{
"groupOp": "|",
"rules": [
{"column": "col2", "op": "==", "value": 2}
{"column": "col3", "op": "==", "value": 3}
]
}
}
This would allow structured storage of the nested condition "col1 == 1 & (col2 == 2 | col3 == 3)", and others of arbitrary depth.
I wrote a recursive function to parse this structure, using the contains function to distinguish the base case from the recursive case. However, I'm running into a stack overflow error. Upon debugging I realized that while "rule" had the correct value, "obj" stayed the same on each recursive call.
parseFilter = Function( {obj},
If (obj << contains("groupOp") & obj << contains("rules"),
str = "(";
For Each({rule}, obj["rules"],
show(rule);
Concat(str, Recurse(rule) || " " || groupOp || " ");
);
Concat(str, ")");
Return(str);
, // else
Return(":" || obj["column"] || " " || obj["op"] || " " || data );
);
);
Is this to do with the For Each function, having an associative array as a parameter, or something else?