{"record":{"id":"89585460bc9b40f9","repo":"json-path/JsonPath","slug":"put-can-not-be-performed-to-multiple-properties","errorCode":null,"errorMessage":"Put can not be performed to multiple properties","messagePattern":"Put can not be performed to multiple properties","errorType":"exception","errorClass":"InvalidModificationException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java","lineNumber":320,"sourceCode":"                    configuration.jsonProvider().setProperty(parent, property, mapFunction.map(currentValue, configuration));\n                }\n            }\n        }\n\n        public void delete(Configuration configuration){\n            for (String property : properties) {\n                configuration.jsonProvider().removeProperty(parent, property);\n            }\n        }\n\n        @Override\n        public void add(Object newVal, Configuration configuration) {\n            throw new InvalidModificationException(\"Add can not be performed to multiple properties\");\n        }\n\n        @Override\n        public void put(String key, Object newVal, Configuration configuration) {\n            throw new InvalidModificationException(\"Put can not be performed to multiple properties\");\n        }\n\n        @Override\n        public void renameKey(String oldKeyName, String newKeyName, Configuration configuration) {\n            throw new InvalidModificationException(\"Rename can not be performed to multiple properties\");\n        }\n\n        @Override\n        public Object getAccessor() {\n            return Utils.join(\"&&\", properties);\n        }\n    }\n}\n","sourceCodeStart":302,"sourceCodeEnd":334,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java#L302-L334","documentation":"PathRef is an internal reference to the JSON location a path resolved to. When a JsonPath with a wildcard/definite multi-match (e.g. '$..[*]' or '$.store.*') resolves to MORE THAN ONE property, calling JsonPath.put() on the result cannot know which single property to modify, so the multi-property PathRef variant unconditionally throws InvalidModificationException. Only modification APIs (put/add/renameKey) are affected; reads still work.","triggerScenarios":"Calling JsonPath.put(json, \"key\", value) (or Configuration.addOperation / com.jayway.jsonpath.DocumentContext.put) where the path expression contains a wildcard or filter that matches multiple properties in an object, e.g. '$.store.book[*].put' or path '$..author' evaluated with a definite path that resolves to several map entries. Any put() on the PathRef whose 'properties' list has more than one element hits PathRef.java:320.","commonSituations":"Developers want to 'set a field on every matched object' using put() with a wildcard path; put() only works when the path points at exactly one property. Also seen after switching from a definite single-path to a '$..*' style path, or when using path() plus explicit PUT operations on multi-valued results.","solutions":["Read the matched objects with JsonPath.read()/DocumentContext, loop over them, and perform the modification per element with a definite path (e.g. '$.store.book[0].price') per index.","Use the map/list returned by read() as plain Java objects, mutate them, and return/re-serialize them instead of using put().","Narrow the path so it resolves to exactly one property (add an index or unique key filter) before calling put()."],"exampleFix":"// before\nJsonPath.put(json, \"$.store.book[*]\", \"inStock\", true); // InvalidModificationException\n// after\nList<Map<String, Object>> books = JsonPath.read(json, \"$.store.book[*]\");\nfor (int i = 0; i < books.size(); i++) {\n    books.get(i).put(\"inStock\", true); // mutate the resolved maps\n}","handlingStrategy":"validation","validationCode":"Object matched = JsonPath.read(json, path);\nboolean isMulti = matched instanceof java.util.List && ((java.util.List<?>) matched).size() > 1;\nif (isMulti) {\n    throw new IllegalStateException(\"Path matches multiple properties; use read+loop instead of put(): \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n    JsonPath.put(json, path, key, value);\n} catch (InvalidModificationException e) {\n    List<Map<String, Object>> items = JsonPath.read(json, path);\n    for (Map<String, Object> item : items) item.put(key, value);\n}","preventionTips":["Only call put()/renameKey() with definite paths resolving to a single property.","Prefer read-then-mutate over in-place put() whenever wildcards are involved.","Test paths against production-shaped data, not single-object fixtures."],"tags":["json-path","wildcard-path","unsupported-operation","multi-match"],"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"}