{"record":{"id":"a0f4e7aac7113b14","repo":"json-path/JsonPath","slug":"expected-character-c","errorCode":null,"errorMessage":"Expected character: %c","messagePattern":"Expected character: %c","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java","lineNumber":222,"sourceCode":"    public char nextSignificantChar() {\n        return nextSignificantChar(position);\n    }\n\n    public char nextSignificantChar(int startPosition) {\n        int readPosition = startPosition + 1;\n        while (!isOutOfBounds(readPosition) && charAt(readPosition) == SPACE) {\n            readPosition++;\n        }\n        if (!isOutOfBounds(readPosition)) {\n            return charAt(readPosition);\n        } else {\n            return ' ';\n        }\n    }\n\n    public void readSignificantChar(char c) {\n        if (skipBlanks().currentChar() != c) {\n            throw new InvalidPathException(String.format(\"Expected character: %c\", c));\n        }\n        incrementPosition(1);\n    }\n\n    public boolean hasSignificantSubSequence(CharSequence s) {\n        skipBlanks();\n        if (! inBounds(position + s.length() - 1)) {\n            return false;\n        }\n        if (! subSequence(position, position + s.length()).equals(s)) {\n            return false;\n        }\n\n        incrementPosition(s.length());\n        return true;\n    }\n\n    public int indexOfPreviousSignificantChar(int startPosition){","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/CharacterIndex.java#L204-L240","documentation":"readSignificantChar skips insignificant whitespace and then requires the next significant character in the path to equal the expected character c. If it differs, the path syntax is invalid at that position and an InvalidPathException with 'Expected character: %c' is thrown. This is a strict syntax check used while tokenizing path segments.","triggerScenarios":"Parsing a malformed path where a mandatory delimiter is missing or replaced — e.g. a filter lacking its opening or closing parenthesis, a missing '.' between segments, or a stray character where a bracket/paren/dot was expected.","commonSituations":"Typos in hand-written paths like \"$.store.book[?(@.price<10\" (missing closing paren); concatenating segments without the correct separator; locale-invisible characters such as non-breaking spaces or smart quotes replacing ASCII delimiters in copied code.","solutions":["Read the message to see which character was expected, then inspect the path around that position and insert/correct the delimiter.","Validate the whole path with JsonPath.compile() and fix the reported syntax error.","Replace fancy Unicode quotes/spaces pasted from editors or web pages with plain ASCII equivalents.","Build paths with constants or a builder instead of ad-hoc string concatenation to avoid malformed expressions."],"exampleFix":"// before\nString path = \"$[?@.price < 10]\"; // missing '(' after '?'\n// after\nString path = \"$[?(@.price < 10)]\";","handlingStrategy":"validation","validationCode":"String normalized = path.replace('\\u00A0', ' ').replace('\\u201C', '\"').replace('\\u201D', '\"');\nJsonPath.compile(normalized); // throws InvalidPathException on any missing delimiter","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.compile(path);\n} catch (InvalidPathException e) {\n    // e.getMessage() names the expected character, e.g. \"Expected character: )\"\n    throw new IllegalArgumentException(\"Syntax error in path '\" + path + \"': \" + e.getMessage(), e);\n}","preventionTips":["Use JsonPath.compile() to validate user-supplied paths before evaluation","Replace smart quotes and non-breaking spaces copied from editors/web pages","Build paths from constants or builders, not loose string concatenation","Check balanced parens/brackets with a simple counter before compiling"],"tags":["json-path","path-parsing","syntax-error","invalid-path"],"backgroundTag":"invalid-argument-format","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}