parse
Parses a string into a JsonPath.
The string to pass needs to conform to a specific format.
It can be a dot (
.) separated list of alphanumeric characters and/or underscores.Each component of a list built this way represents one level of a JSON object.
The last one can represent any type of JSON value.
Square brackets (
[]) could be used instead of the dot notation, to separate one (or each) of the components. Inside these brackets you can put:An integer, to represent an element into a JSON array.
A single (
') or double (") quoted string to represent an element into a JSON object.Inside of the quoted string any character is valid, but the character used to quote the string (
'or") needs to be escaped with a backslash (\), and same for backslashes, which need to be escaped with an additional backslash.
Examples of valid strings:
propertycontainer.propertycontainer["property"]container['property']container["john's party"]container['john\'s party']container["\"nested quote\""]container["escaped\\backslash"]array[123]which is different from
array["123"], although both are valid. Difference is that the quoted version treats thearrayproperty as an object and looks for a nested "123" by string instead of the item at index 123 in an array.array[123].propertysome_propertycontainer.some_propertycontainer["some.property"]which is different from
container.some.property, although both are validcontainer["some@property"]which would be wrong without the quoted brackets:
container.some@property)["array"][123]["property"][1].array[2][1][2][3]
Examples of invalid strings:
"property": invalid character (")container-property: invalid character (-)container[property]: missing quotes (") in bracketscontainer.["property"]: invalid character (.) before the bracketscontainer["property']: closing quote (') different from opening one (") in bracketscontainer['john's party']: unescaped quote (')container[""nested quote""]: unescaped quotes (")container["unescaped\backslash"]: unescaped backslash (\)array[12 3]: invalid number with whitespace ( ) inside index bracketscontainer@property: invalid character (@)
Return
A JsonPath, if the parsing succeeded.
Parameters
: The String that will be parsed.
Throws
if the parsing failed.