diff --git a/JUST.net/ExpressionInterpreter.cs b/JUST.net/ExpressionInterpreter.cs index b65cf3c..18e4b37 100644 --- a/JUST.net/ExpressionInterpreter.cs +++ b/JUST.net/ExpressionInterpreter.cs @@ -31,6 +31,7 @@ public ExpressionInterpreter() /// Initialize core methods /// public void Setup(JToken inputObject, bool strictPathHandling) + { this.strictPathHandling = strictPathHandling; @@ -48,7 +49,7 @@ public void Setup(JToken inputObject, bool strictPathHandling) }; Func nullToString = (value) => value ?? ""; - Func regex= (value, pattern, defaultValue) => + Func regex = (value, pattern, defaultValue) => { var result = Regex.Match(value, pattern); if (result.Success) @@ -57,11 +58,24 @@ public void Setup(JToken inputObject, bool strictPathHandling) return defaultValue; }; + Func createSplitList = (value, separator) => + { + if (value == null) + return new JArray(); + + if (separator == null) + throw new Exception("createSplitList two paramters (value, separator)"); + + var splits = value.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries); + return JArray.FromObject(splits); + }; + SetFunction("valueOf", valueOf); SetFunction("valueOfStr", valueOfStr); SetFunction("valueOfInt", valueOfInt); SetFunction("valueOfDouble", valueOfDouble); SetFunction("nullToString", nullToString); + SetFunction("createSplitList", createSplitList); SetFunction("regex", regex); } diff --git a/JUST.net/JsonTransformer.cs b/JUST.net/JsonTransformer.cs index c88418d..6e4724e 100644 --- a/JUST.net/JsonTransformer.cs +++ b/JUST.net/JsonTransformer.cs @@ -208,7 +208,19 @@ private void RecursiveEvaluate(JToken parentToken, string inputJson, JArray pare expression = expression.Replace("@@\\", @"\\"); var result = expressionInterpreter.Eval(expression); - property.Value = new JValue(result); + + if (result is JArray arrayValue) + { + property.Value = arrayValue; + continue; // Skip further processing + } + if (result is JObject jObject) + { + property.Value = jObject; + continue; // Skip further processing + } + else + property.Value = new JValue(result); } catch (PathNotFoundException ex) {