Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion JUST.net/ExpressionInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public ExpressionInterpreter()
/// Initialize core methods
/// </summary>
public void Setup(JToken inputObject, bool strictPathHandling)

{
this.strictPathHandling = strictPathHandling;

Expand All @@ -48,7 +49,7 @@ public void Setup(JToken inputObject, bool strictPathHandling)
};
Func<string, string> nullToString = (value) => value ?? "";

Func<string, string, string, string> regex= (value, pattern, defaultValue) =>
Func<string, string, string, string> regex = (value, pattern, defaultValue) =>
{
var result = Regex.Match(value, pattern);
if (result.Success)
Expand All @@ -57,11 +58,24 @@ public void Setup(JToken inputObject, bool strictPathHandling)
return defaultValue;
};

Func<string, string, JArray> 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);
}

Expand Down
14 changes: 13 additions & 1 deletion JUST.net/JsonTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down