{"record":{"id":"4484a34678650147","repo":"json-path/JsonPath","slug":"missing-property-in-path","errorCode":null,"errorMessage":"Missing property in path ","messagePattern":"Missing property in path ","errorType":"exception","errorClass":"PathNotFoundException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/PathToken.java","lineNumber":78,"sourceCode":"                        propertyVal =  null;\n                    } else {\n                        if(ctx.options().contains(Option.SUPPRESS_EXCEPTIONS) ||\n                           !ctx.options().contains(Option.REQUIRE_PROPERTIES)){\n                            return;\n                        } else {\n                            throw new PathNotFoundException(\"No results for path: \" + evalPath);\n                        }\n                    }\n                } else {\n                    if (! (isUpstreamDefinite() && isTokenDefinite()) &&\n                       !ctx.options().contains(Option.REQUIRE_PROPERTIES) ||\n                       ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){\n                        // If there is some indefiniteness in the path and properties are not required - we'll ignore\n                        // absent property. And also in case of exception suppression - so that other path evaluation\n                        // branches could be examined.\n                        return;\n                    } else {\n                        throw new PathNotFoundException(\"Missing property in path \" + evalPath);\n                    }\n                }\n            }\n            PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, property) : PathRef.NO_OP;\n            if (isLeaf()) {\n                String idx = \"[\" + String.valueOf(upstreamArrayIndex) + \"]\";\n                if(idx.equals(\"[-1]\") || ctx.getRoot().getTail().prev().getPathFragment().equals(idx)){\n                    ctx.addResult(evalPath, pathRef, propertyVal);\n                }\n            }\n            else {\n                next().evaluate(evalPath, pathRef, propertyVal, ctx);\n            }\n        } else {\n            String evalPath = currentPath + \"[\" + Utils.join(\", \", \"'\", properties) + \"]\";\n\n            assert isLeaf() : \"non-leaf multi props handled elsewhere\";\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/PathToken.java#L60-L96","documentation":"PathNotFoundException thrown by PathToken.handleObjectProperty when the token/upstream is indefinite and the path leaf's property is missing: without REQUIRE_PROPERTIES (which would force the throw path here) or SUPPRESS_EXCEPTIONS to skip it, evaluation still fails because properties are required by default and the requested property is absent.","triggerScenarios":"Evaluating a path with indefinite segments (e.g. $..* or wildcards) ending in a missing property, e.g. JsonPath.read(json, \"$..book.author\") where some matched objects lack 'author', with default options (REQUIRE_PROPERTIES semantics) and no suppression.","commonSituations":"Heterogeneous arrays of objects where only some elements contain the leaf key; querying aggregated API data with optional nested objects.","solutions":["Use Option.SUPPRESS_EXCEPTIONS so branches without the property are skipped instead of throwing","Use Option.DEFAULT_PATH_LEAF_TO_NULL to receive null for the missing property","Restructure the path or filter to only match objects guaranteed to contain the property","Catch PathNotFoundException and handle missing data explicitly"],"exampleFix":"// before\nList<String> authors = JsonPath.read(json, \"$..book.author\");\n// after\nConfiguration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();\nList<String> authors = JsonPath.using(cfg).parse(json).read(\"$..book.author\");","handlingStrategy":"try-catch","validationCode":"DocumentContext ctx = JsonPath.parse(json);\nList<Map<String, Object>> books = ctx.read(\"$..book\");\nboolean allHaveAuthor = books.stream().allMatch(b -> b.containsKey(\"author\"));","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, indefinitePath);\n} catch (PathNotFoundException e) {\n    return Collections.emptyList(); // some branches lacked the property\n}","preventionTips":["Add Option.SUPPRESS_EXCEPTIONS when scanning heterogeneous collections","Filter the collection first so only objects with the leaf key are traversed","Prefer inline filters [?(@.author)] over bare indefinite leaf paths","Test queries against real-world documents with missing optional fields"],"tags":["json-path","path-not-found","missing-property","evaluation"],"backgroundTag":"resource-not-found","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"}