{"record":{"id":"da2a159270fda71a","repo":"json-path/JsonPath","slug":"json-object-is-expected","errorCode":null,"errorMessage":"Json object is expected","messagePattern":"Json object is expected","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/json/JakartaJsonProvider.java","lineNumber":257,"sourceCode":"        } else {\r\n            throw new UnsupportedOperationException();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public boolean isMap(Object obj) {\r\n        return (obj instanceof JsonObject || obj instanceof JsonObjectBuilder);\r\n    }\r\n\r\n    @Override\r\n    public Collection<String> getPropertyKeys(Object obj) {\r\n        Set<String> keys;\r\n        if (obj instanceof JsonObjectBuilder) {\r\n            keys = ((JsonObjectBuilder) obj).build().keySet();\r\n        } else if (obj instanceof JsonObject) {\r\n            keys = ((JsonObject) obj).keySet();\r\n        } else {\r\n            throw new UnsupportedOperationException(\"Json object is expected\");\r\n        }\r\n        return new ArrayList<String>(keys);\r\n    }\r\n\r\n    @Override\r\n    public int length(Object obj) {\r\n        if (isArray(obj)) {\r\n            if (obj instanceof JsonArrayBuilder) {\r\n                return ((JsonArrayBuilder) obj).build().size();\r\n            } else {\r\n                return ((List<?>) obj).size();\r\n            }\r\n        } else if (isMap(obj)) {\r\n            if (obj instanceof JsonObjectBuilder) {\r\n                obj = ((JsonObjectBuilder) obj).build();\r\n            }\r\n            return ((JsonObject) obj).size();\r\n        } else {\r","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/json/JakartaJsonProvider.java#L239-L275","documentation":"getPropertyKeys only supports JsonObjectBuilder and JsonObject; any other node type (JsonArray, JsonString, numbers, null, plain Java objects) triggers UnsupportedOperationException \"Json object is expected\". The caller asked for the key set of something that is not a JSON object.","triggerScenarios":"Calling getPropertyKeys on a node that resolved to an array, scalar, or null — e.g. a JsonPath expression like $.items (an array) or $.missing (null) instead of $.items[0].someObject.","commonSituations":"Iterating keys of a query result that turned out to be an array or absent value due to a wrong path expression or schema drift in the data.","solutions":["Check the node type (instanceof JsonObject) before requesting property keys.","Fix the path expression to select an object member rather than an array or scalar.","For arrays, iterate elements with toIterable/length and call getPropertyKeys per element.","Handle null/missing paths upstream so getPropertyKeys is never called with null."],"exampleFix":"// before\nList<String> keys = provider.getPropertyKeys(node);\n// after\nif (node instanceof JsonObject) {\n    List<String> keys = provider.getPropertyKeys(node);\n}","handlingStrategy":"type-guard","validationCode":"// Java\nif (node == null || !(node instanceof JsonObject || node instanceof JsonObjectBuilder)) {\n    throw new IllegalStateException(\"Expected JSON object at path\");\n}","typeGuard":"// Java\nstatic boolean isJsonObject(Object o) {\n    return o instanceof JsonObject || o instanceof JsonObjectBuilder;\n}","tryCatchPattern":"try { keys = provider.getPropertyKeys(node); } catch (UnsupportedOperationException e) { keys = Collections.emptyList(); }","preventionTips":["Verify path expressions resolve to objects, not arrays/scalars","Handle MISSING/null query results before key extraction","Schema-check upstream payloads"],"tags":["json-p","type-mismatch","unsupported-operation"],"backgroundTag":"incompatible-source-type","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"}