Skip to content

Different behaviour than on jsonLogic.com for some operators #11

@kph21

Description

@kph21

Hi, my team and I recently discovered that the "+" and "*" operators don't work exactly as documented on the jsonLogic site. It appears like your implementation avoids having null values when working with these operators and tries to return a non-null value while the jsonLogic site returns null.

i.e. for 0 + null, jsonLogic site returns null while this library returns 0.

However, we have a use case to return null when evaluating the logic and have thus implemented the following operators:

operators.DeleteOperator("+");
operators.AddOperator("+", (p, args, data) => Min2From(args.Select(a => p.Apply(a, data))).Aggregate((prev, next) =>
            {
                try { return prev != null ? (double?)(Convert.ToDouble(prev) + Convert.ToDouble(next)) : null; }
                catch { return prev.ToString() + next.ToString(); }
            }));

operators.DeleteOperator("*");
operators.AddOperator("*", ReduceDoubleArgs(null, (prev, next) => (next == null) ? null : prev * next));

Perhaps this support for returning null values can be added as part of some settings, should you see fit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions