protected virtual void Assert(JmesPathExpression expression, string input, string expected)
        {
            var json   = JmesPath.ParseJson(input);
            var result = expression.Transform(json);
            var actual = result.AsJToken().AsString();

            Xunit.Assert.Equal(expected, actual);
        }
Exemple #2
0
        protected JToken Evaluate(JmesPathExpression expression, JToken token)
        {
            var eval = expression.Transform(token).AsJToken();
            var type = eval.GetTokenType();

            if (type != "number" && type != "string")
            {
                throw new Exception($"Error: invalid-type, the expression argument of function {Name} should return a number or a string.");
            }

            if (type == "number")
            {
                return(eval);
            }

            double number;

            if (double.TryParse(eval.Value <string>(), out number))
            {
                return(new JValue(number));
            }

            throw new Exception("Error: invalid-type, when evaluating the expression argument of function {Name}, some items could not be cast to a number.");
        }
Exemple #3
0
 protected override JmesPathArgument Transform(JToken json)
 {
     return(expression_.Transform(json));
 }