{"record":{"id":"56794287c3cb8b5e","repo":"json-path/JsonPath","slug":"invalidjsonexception","errorCode":null,"errorMessage":"InvalidJsonException","messagePattern":"InvalidJsonException","errorType":"exception","errorClass":"InvalidJsonException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/json/Jackson3JsonProvider.java","lineNumber":75,"sourceCode":"    }\n\n    /**\n     * Initialize the JacksonProvider with a custom ObjectMapper and ObjectReader.\n     *\n     * @param objectMapper the ObjectMapper to use\n     * @param objectReader the ObjectReader to use\n     */\n    public Jackson3JsonProvider(ObjectMapper objectMapper, ObjectReader objectReader) {\n        this.objectMapper = objectMapper;\n        this.objectReader = objectReader;\n    }\n\n    @Override\n    public Object parse(String json) throws InvalidJsonException {\n        try {\n            return objectReader.readValue(json);\n        } catch (JacksonException e) {\n            throw new InvalidJsonException(e, json);\n        }\n    }\n\n    @Override\n    public Object parse(byte[] json) throws InvalidJsonException {\n        try {\n            return objectReader.readValue(json);\n        } catch (JacksonException e) {\n            throw new InvalidJsonException(e, new String(json, StandardCharsets.UTF_8));\n        }\n    }\n\n    @Override\n    public Object parse(InputStream jsonStream, String charset) throws InvalidJsonException {\n        try {\n            return objectReader.readValue(new InputStreamReader(jsonStream, charset));\n        } catch (IOException e) {\n            throw new InvalidJsonException(e);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/json/Jackson3JsonProvider.java#L57-L93","documentation":"Jackson3JsonProvider.parse delegates to Jackson's ObjectMapper/ObjectReader readValue. When the input string/bytes are not valid JSON (syntax error, unexpected token, truncated input), Jackson throws a JacksonException, which the provider wraps in InvalidJsonException carrying the offending input as the message/cause.","triggerScenarios":"Calling JsonPath.parse(String) or parse(byte[]) with malformed JSON — trailing commas, unquoted keys, single quotes, truncated responses, HTML error pages instead of JSON, empty or whitespace-only input.","commonSituations":"Consuming HTTP APIs that return HTML error pages with 200/500 status; logging/truncated payloads persisted and later parsed; wrong charset/encoding corrupting bytes; hand-edited JSON fixtures.","solutions":["Validate the payload is well-formed JSON before parsing (or catch InvalidJsonException and inspect getCause())","Log the raw input when parsing fails to spot HTML/truncated responses","Check HTTP status/content-type before parsing response bodies","Fix the source producing invalid JSON (serializer config, encoding, truncation)"],"exampleFix":"// before\nDocumentContext ctx = JsonPath.parse(responseBody); // InvalidJsonException on HTML error pages\n// after\nif (response.getStatus() == 200 && response.getContentType().contains(\"application/json\")) {\n    DocumentContext ctx = JsonPath.parse(responseBody);\n} else {\n    throw new ApiException(\"non-JSON response: \" + response.getStatus());\n}","handlingStrategy":"try-catch","validationCode":"if (body == null || body.trim().isEmpty()) throw new IllegalArgumentException(\"empty JSON input\");\n// optional strict pre-check with Jackson:\nobjectReader.readTree(body); // throws on malformed JSON before JsonPath sees it","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.parse(body);\n} catch (InvalidJsonException e) {\n    log.error(\"invalid JSON: {}\", body, e.getCause());\n    throw new IllegalArgumentException(\"payload is not valid JSON\", e);\n}","preventionTips":["Validate HTTP status and content-type before parsing bodies","Log raw payloads on parse failure to diagnose HTML/truncated input","Sanitize fixtures and avoid hand-editing JSON","Run JSON payloads through a validator in CI contract tests"],"tags":["json-path","jackson","invalid-json","parsing"],"backgroundTag":"json-parse-error","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"}