{"record":{"id":"a63900d502c53c92","repo":"json-path/JsonPath","slug":"setproperty-operation-cannot-be-used-with","errorCode":null,"errorMessage":"setProperty operation cannot be used with ","messagePattern":"setProperty operation cannot be used with ","errorType":"exception","errorClass":"JsonPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java","lineNumber":93,"sourceCode":"            return JsonProvider.UNDEFINED;\n        } else {\n            return m.get(key);\n        }\n    }\n\n    /**\n     * Sets a value in an object\n     *\n     * @param obj   an object\n     * @param key   a String key\n     * @param value the value to set\n     */\n    @SuppressWarnings(\"unchecked\")\n    public void setProperty(Object obj, Object key, Object value) {\n        if (isMap(obj))\n            ((Map) obj).put(key.toString(), value);\n        else {\n            throw new JsonPathException(\"setProperty operation cannot be used with \" + obj!=null?obj.getClass().getName():\"null\");\n        }\n    }\n\n\n\n    /**\n     * Removes a value in an object or array\n     *\n     * @param obj   an array or an object\n     * @param key   a String key or a numerical index to remove\n     */\n    @SuppressWarnings(\"unchecked\")\n    public void removeProperty(Object obj, Object key) {\n        if (isMap(obj))\n            ((Map) obj).remove(key.toString());\n        else {\n            List list = (List) obj;\n            int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L75-L111","documentation":"AbstractJsonProvider.setProperty mutates an object by putting a key/value into a JSON object (Map). If the target object is not a Map, the provider cannot set a property and throws JsonPathException. Note the message has an operator-precedence bug ('+' binds tighter than '!='), so the text may be garbled, but the cause is always a non-object target.","triggerScenarios":"Calling Configuration.defaultConfiguration().jsonProvider().setProperty(listOrString, key, value); using JsonPath's mapFunction/put-style helpers (e.g. using(JsonPath).put(...)/ParseContext set operations) against a JSON array, string, or number instead of an object; passing null as the target object.","commonSituations":"Document-generation code that assumes a node is an object but the parsed JSON has it as an array or scalar; mutating documents where the path resolved to the wrong node; generic JSON transformation pipelines applying object updates to every node type.","solutions":["Verify the target is a JSON object before calling setProperty (jsonProvider.isMap(obj))","Convert the target to an object first or correct the path so it points at an object node","For arrays/strings, use the appropriate provider operations (array add, length, etc.) instead of property set","Guard against null targets explicitly before mutation"],"exampleFix":"// before\nprovider.setProperty(target, \"key\", value); // throws when target is a List\n// after\nif (provider.isMap(target)) {\n    provider.setProperty(target, \"key\", value);\n} else {\n    throw new IllegalArgumentException(\"target is not a JSON object\");\n}","handlingStrategy":"type-guard","validationCode":"if (obj == null || !provider.isMap(obj)) throw new IllegalArgumentException(\"setProperty target must be a JSON object\");","typeGuard":"boolean canSetProperty(Object o) { return o instanceof Map<?, ?>; }","tryCatchPattern":"try {\n    provider.setProperty(obj, key, value);\n} catch (JsonPathException e) {\n    // obj was not a JSON object — handle non-object branch\n}","preventionTips":["Check jsonProvider.isMap(obj) before mutation","Resolve the target via a path that is known to point at an object","Handle null targets explicitly","Validate document shape before generic transformation passes"],"tags":["json-path","set-property","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}