public ActionResult <PathQueryOutput> QueryPath([FromBody] PathQueryInput input) { if (!ModelState.IsValid) { return(BadRequest(new LogicProcessOutput { Errors = ModelState.Root.GetErrors().ToList() })); } var path = JsonPath.Parse(input.Path); var data = input.Data.RootElement; var options = new PathEvaluationOptions { ExperimentalFeatures = { ProcessDataReferences = input.Options?.ResolveReferences ?? false } }; var result = path.Evaluate(data, options); return(Ok(new PathQueryOutput { Result = result })); }
public void ProblemStatementExample() { #pragma warning disable 1998 var options = new PathEvaluationOptions { ExperimentalFeatures = { ProcessDataReferences = true, DataReferenceDownload = async uri => uri.OriginalString == "http://example.com/11" ? JsonDocument.Parse("{ \"c\": { \"d\": \"Hello\" } }") : null } }; #pragma warning restore 1998 using var instance = JsonDocument.Parse("{ \"a\": { \"b\": {\"$ref\": \"http://example.com/11\" } } }"); var path = JsonPath.Parse("$.a.b.c.d"); var results = path.Evaluate(instance.RootElement, options); Assert.AreEqual(1, results.Matches.Count); Assert.AreEqual("Hello", results.Matches[0].Value.GetString()); }