WorkMaze / JUST.net

JUST - JSON Under Simple Transformation (XSLT equivalent for JSON).
MIT License
171 stars 54 forks source link

Exception on ifcondition on null node #139

Open eduardomb08 opened 3 years ago

eduardomb08 commented 3 years ago

The functions ifcondition, stringequals and stringcontains are currently throwing an exception when the first parameter is null. The first parameter would be null if the value of a node is passed as that first parameter and the node does is not actually present in the json document. The following sample code reproduces the behavior:

var input = @"{ ""id"": ""12345"" }";

var transformer = @"{
    ""#"": ""#valueof($)"",
    ""newName"": ""#ifcondition(#valueof($.name),,awesome,not awesome)""
}";

var output = new JsonTransformer().Transform(transformer, input);

//var jobj = JsonConvert.DeserializeObject(output);
//var pretty = JsonConvert.SerializeObject(jobj, Formatting.Indented);
//Console.WriteLine(pretty);

I believe this is not the best behavior. It should evaluate the conditionals to false, but not throw an exception.

I will submit a PR with a suggestion on a fix.

Courela commented 3 years ago

I agree if EvaluationMode is set to 'FallbackToDefault', default value. If set to 'Strict' it should throw an exception, 'Strict' mode is exactly to prevent that, functions not able to complete successfully.