{"record":{"id":"46823032af6faf30","repo":"json-path/JsonPath","slug":"unable-to-parse-unicode-value-s","errorCode":null,"errorMessage":"Unable to parse unicode value: %s","messagePattern":"Unable to parse unicode value: (.+?)","errorType":"exception","errorClass":"JsonPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java","lineNumber":193,"sourceCode":"        }\n        int len = str.length();\n        StringWriter writer = new StringWriter(len);\n        StringBuilder unicode = new StringBuilder(4);\n        boolean hadSlash = false;\n        boolean inUnicode = false;\n        for (int i = 0; i < len; i++) {\n            char ch = str.charAt(i);\n            if (inUnicode) {\n                unicode.append(ch);\n                if (unicode.length() == 4) {\n                    try {\n                        int value = Integer.parseInt(unicode.toString(), 16);\n                        writer.write((char) value);\n                        unicode.setLength(0);\n                        inUnicode = false;\n                        hadSlash = false;\n                    } catch (NumberFormatException nfe) {\n                        throw new JsonPathException(\"Unable to parse unicode value: \" + unicode, nfe);\n                    }\n                }\n                continue;\n            }\n            if (hadSlash) {\n                hadSlash = false;\n                switch (ch) {\n                    case '\\\\':\n                        writer.write('\\\\');\n                        break;\n                    case '\\'':\n                        writer.write('\\'');\n                        break;\n                    case '\\\"':\n                        writer.write('\"');\n                        break;\n                    case 'r':\n                        writer.write('\\r');","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java#L175-L211","documentation":"Utils.unescape() processes JSON string escape sequences, including \\uXXXX. When the four hex digits after \\u are not valid hexadecimal (e.g. \\u12zz), Integer.parseInt(...,16) throws NumberFormatException, which is rethrown as JsonPathException with this message. It indicates malformed input or an incorrectly pre-processed string being fed to the parser.","triggerScenarios":"Parsing a JSON document (or a string containing escapes) where a \\u escape is followed by fewer than 4 hex characters or invalid hex characters, e.g. \"\\uGG12\" or a truncated \"\\u12\" at the end of a string.","commonSituations":"Consuming hand-built or double-escaped JSON, copying payloads from logs where backslashes were mangled, strings that were already decoded once so remaining '\\u' is literal data rather than a valid escape, or non-JSON text fed into JsonPath.parse().","solutions":["Fix the source string so every \\u escape is followed by exactly 4 hexadecimal digits.","Unescape/massage the text correctly before parsing (account for double escaping: '\\\\u0041' in raw bytes).","Validate input with a strict JSON parser first to get a precise location of the malformed escape."],"exampleFix":"// before\nString bad = \"{\\\"name\\\": \\\"\\\\u12zz\\\"}\"; // \\u12zz is not valid hex\n// after\nString good = \"{\\\"name\\\": \\\"\\\\u12FF\\\"}\"; // exactly 4 hex digits","handlingStrategy":"try-catch","validationCode":"java.util.regex.Pattern HEX = java.util.regex.Pattern.compile(\"\\\\\\\\\\\\\\\\u[0-9a-fA-F]{4}\");\n// reject any \\u not followed by exactly 4 hex digits before parsing\nif (!HEX.matcher(input).find() && input.contains(\"\\\\u\")) {\n    throw new IllegalArgumentException(\"Malformed unicode escape in input\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    DocumentContext ctx = JsonPath.parse(raw);\n} catch (JsonPathException e) {\n    if (e.getMessage().startsWith(\"Unable to parse unicode value\")) {\n        // fix escaping / re-decode source, then retry once\n    } else throw e;\n}","preventionTips":["Parse with a strict JSON parser first to localize malformed escapes.","Beware double-escaped sources (logs, HTTP bodies read as text).","Never feed non-JSON text into JsonPath.parse()."],"tags":["json-path","unicode-escape","string-parsing","malformed-input"],"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"}