Function parse

Source
pub fn parse(str: &str) -> Result<JsonPathQuery>
Expand description

Parse a JSONPath query string using default Parser configuration.

§Errors

Fails if the string does not represent a valid JSONPath query as governed by the JSONPath RFC specification.

Note that leading and trailing whitespace is explicitly disallowed by the spec. This can be relaxed with a custom Parser configured with ParserBuilder::allow_surrounding_whitespace.

§Examples

let x = "  $.a  ";
let err = rsonpath_syntax::parse(x).expect_err("should fail");
assert_eq!(err.to_string(),
"error: query starting with whitespace

    $.a  
  ^^ leading whitespace is disallowed
  (bytes 0-1)


error: query ending with whitespace

    $.a  
       ^^ trailing whitespace is disallowed
  (bytes 5-6)


suggestion: did you mean `$.a` ?
");