{"record":{"id":"f2ef83a8ac8f50e6","repo":"json-path/JsonPath","slug":"rename-can-not-be-performed-to-multiple-properties","errorCode":null,"errorMessage":"Rename can not be performed to multiple properties","messagePattern":"Rename 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":325,"sourceCode":"        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":307,"sourceCodeEnd":334,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java#L307-L334","documentation":"Same internal PathRef constraint as the put() case: when a path resolves to multiple properties, the multi-property PathRef cannot rename a single key unambiguously, so renameKey() throws InvalidModificationException. Renaming is only supported on a path that points at exactly one object property.","triggerScenarios":"Calling JsonPath.renameKey(json, path, oldKey, newKey) where the given path matches more than one property (wildcards, deep-scan '$..', or filters resolving to several map entries). PathRef.renameKey with multiple 'properties' throws at PathRef.java:325.","commonSituations":"Bulk-renaming a field across an array of objects with '$.items[*]' or '$..oldName' paths; works in tests with single objects, fails in production data where the path matches several entries.","solutions":["Iterate over matched objects from read() and rename the key manually on each Map (put new key, remove old key).","Call renameKey once per definite path (e.g. '$.items[0]', '$.items[1]', ...) that resolves to a single property.","Narrow the path with a unique filter/index so exactly one property is matched before renaming."],"exampleFix":"// before\nJsonPath.renameKey(json, \"$..id\", \"id\", \"bookId\"); // InvalidModificationException on multi-match\n// after\nList<Map<String, Object>> items = JsonPath.read(json, \"$..items[*]\");\nfor (Map<String, Object> item : items) {\n    Object v = item.remove(\"id\");\n    item.put(\"bookId\", v);\n}","handlingStrategy":"validation","validationCode":"Object matched = JsonPath.read(json, path);\nif (matched instanceof java.util.List && ((java.util.List<?>) matched).size() != 1) {\n    throw new IllegalStateException(\"renameKey requires a single-property path, got: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n    JsonPath.renameKey(json, path, oldKey, newKey);\n} catch (InvalidModificationException e) {\n    List<Map<String, Object>> items = JsonPath.read(json, path);\n    for (Map<String, Object> m : items) { Object v = m.remove(oldKey); if (v != null) m.put(newKey, v); }\n}","preventionTips":["Avoid deep-scan ($..) and wildcard paths with renameKey.","Rename keys by iterating maps manually when the target may repeat.","Keep one rename per definite path segment."],"tags":["json-path","wildcard-path","unsupported-operation","rename-key"],"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"}