Interface ParseError

All Known Implementing Classes:
ParseError.ArgumentTypeMismatch, ParseError.ControlCharacter, ParseError.IntegerOutOfRange, ParseError.InvalidEscape, ParseError.InvalidInteger, ParseError.InvalidUtf8, ParseError.LiteralWithoutComparison, ParseError.NestingTooDeep, ParseError.NonSingularQuery, ParseError.NotComparable, ParseError.NumberOutOfRange, ParseError.UnexpectedCharacter, ParseError.UnexpectedEnd, ParseError.UnknownFunction, ParseError.UnpairedSurrogate, ParseError.ValueTypeInTest, ParseError.WrongArgumentCount

The reason why a query is not well-formed or not valid (RFC 9535, Section 2.1).

Each error is a record, so a switch can match the errors that need special handling. message() gives a description of all errors:

String describe = switch (JsonPathParser.standard().parse("$[?length(@.*) > 3]")) {
    case Result.Ok(JsonPathQuery query) -> "valid: " + query;
    case Result.Err(ParseError.NonSingularQuery(int position)) ->
            "@.* can select more than one node, at position " + position;
    case Result.Err(ParseError.UnknownFunction(int position, String name)) ->
            "no function " + name;
    case Result.Err(ParseError error) -> error.message(); // all other errors
};
// describe: "@.* can select more than one node, at position 10"

Errors

Error Example query
ParseError.UnexpectedCharacter $.a b, $[?@.a = 1]
ParseError.UnexpectedEnd $[0, $['a
ParseError.InvalidUtf8 bytes that are not UTF-8
ParseError.UnpairedSurrogate a string with half of a surrogate pair
ParseError.ControlCharacter a string literal with an unescaped tab character
ParseError.InvalidEscape $['\a']
ParseError.InvalidInteger $[01], $[-0]
ParseError.IntegerOutOfRange $[9007199254740992]
ParseError.NumberOutOfRange $[?@ == 1e99999999999]
ParseError.UnknownFunction $[?foo(@)]
ParseError.WrongArgumentCount $[?length() == 1]
ParseError.ArgumentTypeMismatch $[?count(1) == 1]
ParseError.NonSingularQuery $[?@.* == 1], $[?length(@.*) == 1]
ParseError.NotComparable $[?match(@, 'a') == true]
ParseError.ValueTypeInTest $[?length(@)]
ParseError.LiteralWithoutComparison $[?1], $[?true]
ParseError.NestingTooDeep more than JsonPathParser.MAX_NESTING_DEPTH nested parentheses

Positions

Each error has a position. For query text, the position is the index of a UTF-16 code unit in the text. For UTF-8 bytes, ParseError.InvalidUtf8 gives the index of a byte; all other errors give the index in the decoded text.

  • Method Details

    • position

      int position()
      Returns the position of the error.
      Returns:
      the position of the error
    • message

      default String message()
      Returns a description of the error.
      Returns:
      a description of the error, with the position