Open jpeckham opened 3 years ago
I cannot seem to to get the JmesPath example to work. using 4.0.0.0
using System; using System.IO; using JUST; public class Program { public static void Main() { // you will have to escape your doublequotes ie "" //read input from JSON file string input = @" { ""locations"": [ { ""name"": ""Seattle"", ""state"": ""WA"" }, { ""name"": ""New York"", ""state"": ""NY"" }, { ""name"": ""Bellevue"", ""state"": ""WA"" }, { ""name"": ""Olympia"", ""state"": ""WA"" } ] } "; //read the transformer from a JSON file string transformer = @" { ""result"": ""#valueof(locations[?state == 'WA'].name | sort(@) | {WashingtonCities: join(', ', @)})"" } "; // with context JUSTContext context = new JUSTContext { EvaluationMode = EvaluationMode.Strict, DefaultDecimalPlaces = 4 }; string transformedString = new JsonTransformer(context).Transform(transformer, input); Console.WriteLine(transformedString); } }
gives error
Unhandled exception. System.Exception: Error while calling function : #valueof(locations[?state == 'WA'].name | sort(@) | {WashingtonCities: join(', ', @)}) - Unexpected character while parsing path indexer: s ---> Newtonsoft.Json.JsonException: Unexpected character while parsing path indexer: s at JUST.ExceptionHelper.HandleException(Exception ex, EvaluationMode evaluationMode) at JUST.ReflectionHelper.Caller[T](Assembly assembly, String myclass, String mymethod, Object[] parameters, Boolean convertParameters, JUSTContext context) at JUST.JsonTransformer`1.ParseFunction(String functionString, JArray array, JToken currentArrayElement) --- End of inner exception stack trace --- at JUST.JsonTransformer`1.ParseFunction(String functionString, JArray array, JToken currentArrayElement) at JUST.JsonTransformer`1.RecursiveEvaluate(JToken parentToken, JArray parentArray, JToken currentArrayToken) at JUST.JsonTransformer`1.Transform(JObject transformer, JToken input) at JUST.JsonTransformer`1.Transform(String transformerJson, JToken input) at JUST.JsonTransformer`1.Transform(String transformerJson, String inputJson) at Program.Main()
It's not explicit enough, you'll have to do this:
string transformedString = new JsonTransformer<JmesPathSelectable>(context).Transform(transformer, input);
I cannot seem to to get the JmesPath example to work. using 4.0.0.0
gives error