{"record":{"id":"1cc4336e62a9622f","repo":"json-path/JsonPath","slug":"unexpected-close-brace-at-character-position","errorCode":null,"errorMessage":"Unexpected close brace '}' at character position: ","messagePattern":"Unexpected close brace '\\}' at character position: ","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java","lineNumber":337,"sourceCode":"                        groupQuote--;\n                    }\n                    else {\n                        groupQuote++;\n                    }\n                    break;\n                case OPEN_PARENTHESIS:\n                    groupParen++;\n                    break;\n                case OPEN_BRACE:\n                    groupBrace++;\n                    break;\n                case OPEN_SQUARE_BRACKET:\n                    groupBracket++;\n                    break;\n\n                case CLOSE_BRACE:\n                    if (0 == groupBrace) {\n                        throw new InvalidPathException(\"Unexpected close brace '}' at character position: \" + path.position());\n                    }\n                    groupBrace--;\n                    break;\n                case CLOSE_SQUARE_BRACKET:\n                    if (0 == groupBracket) {\n                        throw new InvalidPathException(\"Unexpected close bracket ']' at character position: \" + path.position());\n                    }\n                    groupBracket--;\n                    break;\n\n                // In either the close paren case where we have zero paren groups left, capture the parameter, or where\n                // we've encountered a COMMA do the same\n                case CLOSE_PARENTHESIS:\n                    groupParen--;\n                    //CS304 Issue link: https://github.com/json-path/JsonPath/issues/620\n                    if (0 > groupParen || priorChar == '(') {\n                        parameter.append(c);\n                    }","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java#L319-L355","documentation":"InvalidPathException thrown by PathCompiler.parseFunctionParameters when a '}' is encountered while parsing a function's argument list but no matching '{' group is open (groupBrace == 0). The compiler tracks brace nesting while scanning function parameters; an unmatched closer means the path expression is malformed.","triggerScenarios":"Compiling a JSON path with a function call (e.g. $..book.length()) whose parameter text contains an unmatched '}', such as $.foo.concat('}', ) or a brace appearing before any opening brace inside the parentheses.","commonSituations":"Typos in filter expressions, user-supplied path strings from config or HTTP input, template interpolation injecting stray '}' characters into the path.","solutions":["Fix the path string so every '{' inside the function arguments is balanced with a '}'","Escape or remove literal brace characters that are not meant as path syntax","Validate user-supplied path strings with a try { JsonPath.compile(p) } before using them in queries"],"exampleFix":"// before\nJsonPath.read(json, \"$.items.concat('{')\")\n// after\nJsonPath.read(json, \"$.items.concat('{}')\")","handlingStrategy":"validation","validationCode":"static boolean isBalanced(String path) {\n    int depth = 0;\n    for (char c : path.toCharArray()) {\n        if (c == '{') depth++;\n        if (c == '}' && --depth < 0) return false;\n    }\n    return depth == 0;\n}\nif (!isBalanced(path)) throw new IllegalArgumentException(\"Unbalanced braces in path: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n    DocumentContext ctx = JsonPath.parse(json).read(path);\n} catch (InvalidPathException e) {\n    log.warn(\"Malformed path: {}\", path, e);\n}","preventionTips":["Never interpolate raw user input containing braces into path strings","Run JsonPath.compile() on all paths at startup/config load to fail fast","Escape literal brace characters before embedding them in function arguments"],"tags":["json-path","path-compiler","unbalanced-braces","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"}