{"record":{"id":"65c977d6f09af244","repo":"spring-projects/spring-ai","slug":"invalid-json-pointer-s","errorCode":null,"errorMessage":"Invalid JSON Pointer: %s","messagePattern":"Invalid JSON Pointer: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-commons/src/main/java/org/springframework/ai/reader/JsonReader.java","lineNumber":128,"sourceCode":"\t\t}\n\t\telse {\n\t\t\treturn Collections.singletonList(parseJsonNode(rootNode, JsonMapper.shared()));\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves documents from the JSON resource using a JSON Pointer.\n\t * @param pointer A JSON Pointer string (RFC 6901) to locate the desired element\n\t * @return A list of Documents parsed from the located JSON element\n\t * @throws RuntimeException if the JSON cannot be parsed or the pointer is invalid\n\t */\n\tpublic List<Document> get(String pointer) {\n\t\ttry {\n\t\t\tJsonNode rootNode = JsonMapper.shared().readTree(this.resource.getInputStream());\n\t\t\tJsonNode targetNode = rootNode.at(pointer);\n\n\t\t\tif (targetNode.isMissingNode()) {\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid JSON Pointer: \" + pointer);\n\t\t\t}\n\n\t\t\treturn get(targetNode);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Error reading JSON resource\", e);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":110,"sourceCodeEnd":139,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-commons/src/main/java/org/springframework/ai/reader/JsonReader.java#L110-L139","documentation":"JsonReader.get(String pointer) evaluates a JSON Pointer (RFC 6901) against the parsed document; if the pointer resolves to a missing node, it throws IllegalArgumentException('Invalid JSON Pointer: ...'). This signals the path syntax or structure doesn't match the actual JSON.","triggerScenarios":"jsonReader.get(\"/wrong/path\") where the path doesn't exist, or malformed pointer syntax (missing leading '/', unescaped '~' or '/' in keys).","commonSituations":"Hardcoded pointers after the JSON schema changed, keys with '/' or '~' that need escaping (~1, ~0), or array index out of bounds in the pointer.","solutions":["Inspect the actual JSON structure and correct the pointer path","Escape special characters: '~' as ~0, '/' as ~1 in key names","Validate the pointer against the document before calling get(): root.at(pointer).isMissingNode()","Catch IllegalArgumentException and use pointer-less get() to process the whole document"],"exampleFix":"// before\nList<Document> docs = jsonReader.get(\"/data/items\"); // key is actually 'results'\n// after\nList<Document> docs = jsonReader.get(\"/data/results\");","handlingStrategy":"validation","validationCode":"JsonNode root = JsonMapper.shared().readTree(resource.getInputStream());\nif (root.at(pointer).isMissingNode()) {\n    throw new IllegalArgumentException(\"Pointer not found: \" + pointer);\n}","typeGuard":null,"tryCatchPattern":"try {\n    docs = jsonReader.get(pointer);\n} catch (IllegalArgumentException e) {\n    docs = jsonReader.get(); // process whole document instead\n}","preventionTips":["Escape '~' as ~0 and '/' as ~1 in key names","Re-verify pointers after JSON schema changes","Test pointers against a sample of the real payload"],"tags":["json","json-pointer","path"],"backgroundTag":"invalid-argument-format","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}