Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to validate if a syntax of jsonpath is correct?

Hi I am trying to find a way to validate jsonpath entered by user before evaluating it. I was hoping use something like a regex to do that but so far I could not find any doc/resource on how to validate jsonpath syntax.

All searched return resources that talk about evaluating the expression. Even the jayway.JsonPath library does not seem to do any syntax check.

Is it not possible to do a syntax check for jsonpath syntax ? If it is possible can you please point me in the right direction.

like image 984
Rajind Ruparathna Avatar asked Oct 14 '16 00:10

Rajind Ruparathna


People also ask

How do I know if JSON format is correct?

The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then use the IsValid(JToken, JsonSchema) method with the JSON Schema. To get validation error messages, use the IsValid(JToken, JsonSchema, IList<String> ) or Validate(JToken, JsonSchema, ValidationEventHandler) overloads.

How do you evaluate a JSON path?

You can open up a window to evaluate JSONPath expressions by going to Edit -> Find -> "Evaluate JSONPath Expression...". If a JSON file is open, it will use this file to evaluate the expression. If you have JSONPath expressions as Strings in code, use "inject language" and say this is a JSONPath expression.

How do I check if a string is valid in JSON?

In order to check the validity of a string whether it is a JSON string or not, We're using the JSON. parse()method with few variations. This method parses a JSON string, constructs the JavaScript value or object specified by the string.


1 Answers

try JsonPath.compile("$.path")

like image 151
VG P Avatar answered Oct 19 '22 13:10

VG P