{"record":{"id":"2b8229cc6ba17e5d","repo":"json-path/JsonPath","slug":"no-results-for-key-s-found-in-map","errorCode":null,"errorMessage":"No results for Key %s found in map!","messagePattern":"No results for Key (.+?) found in map!","errorType":"exception","errorClass":"PathNotFoundException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java","lineNumber":63,"sourceCode":"\n    abstract Object getAccessor();\n\n    public abstract void set(Object newVal, Configuration configuration);\n\n    public abstract void convert(MapFunction mapFunction, Configuration configuration);\n\n    public abstract void delete(Configuration configuration);\n\n    public abstract void add(Object newVal, Configuration configuration);\n\n    public abstract void put(String key, Object newVal, Configuration configuration);\n\n    public abstract void renameKey(String oldKey,String newKeyName, Configuration configuration);\n\n    protected void renameInMap(Object targetMap, String oldKeyName, String newKeyName, Configuration configuration){\n        if(configuration.jsonProvider().isMap(targetMap)){\n            if(configuration.jsonProvider().getMapValue(targetMap, oldKeyName) == JsonProvider.UNDEFINED){\n                throw new PathNotFoundException(\"No results for Key \"+oldKeyName+\" found in map!\");\n            }\n            configuration.jsonProvider().setProperty(targetMap, newKeyName, configuration.jsonProvider().getMapValue(targetMap, oldKeyName));\n            configuration.jsonProvider().removeProperty(targetMap, oldKeyName);\n        } else {\n            throw new InvalidModificationException(\"Can only rename properties in a map\");\n        }\n    }\n\n    protected boolean targetInvalid(Object target){\n        return target == JsonProvider.UNDEFINED || target == null;\n    }\n\n    @Override\n    public int compareTo(PathRef o) {\n        return this.getAccessor().toString().compareTo(o.getAccessor().toString()) * -1;\n    }\n\n    public static PathRef create(Object obj, String property){","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java#L45-L81","documentation":"PathRef.renameInMap renames a key inside a JSON map via the configured JsonProvider. Before renaming it checks getMapValue for the old key; if the value is UNDEFINED the key does not exist in that map, so it throws PathNotFoundException. The rename operation can only act on keys that are actually present at the resolved location.","triggerScenarios":"Calling JsonPath.renameKey(path, oldKey, newKey, configuration) where the path resolves to a map that does not contain oldKey (typo, wrong casing, or the path pointed at a sibling object).","commonSituations":"Renaming a key whose name differs only by case; renaming a nested key using a parent path instead of the path to the key itself; schema changes where the key was already renamed by another step.","solutions":["Verify oldKeyName exists in the target map (JsonPath.read(document, path) beforehand) and correct the spelling/casing.","Use a path that points exactly at the map containing the key, not an ancestor or sibling.","Guard the rename in a try/catch for PathNotFoundException if key absence is an acceptable outcome.","Check the key in the raw JSON (or provider) before invoking renameKey."],"exampleFix":"// before\njsonPath.renameKey(doc, \"$.user\", \"emial\", \"email\", conf);\n// after\nif (jsonPath.read(doc, \"$.user.emial\") != null) {\n    jsonPath.renameKey(doc, \"$.user.emial\", \"emial\", \"email\", conf);\n}","handlingStrategy":"validation","validationCode":"Object target = JsonPath.read(document, containingMapPath);\nMap<?,?> map = (Map<?,?>) target;\nif (map == null || !map.containsKey(oldKey)) {\n    throw new IllegalArgumentException(\"Key '\" + oldKey + \"' not present at \" + containingMapPath);\n}","typeGuard":"boolean isRenameable(Object o, String key, Configuration conf) {\n    return o != null && conf.jsonProvider().isMap(o)\n        && conf.jsonProvider().getMapValue(o, key) != JsonPath.UNDEFINED;\n}","tryCatchPattern":"try {\n    JsonPath.renameKey(document, path, oldKey, newKey, conf);\n} catch (PathNotFoundException e) {\n    log.warn(\"Key {} not found at {}; skipping rename\", oldKey, path);\n}","preventionTips":["Verify the key exists with a read before renaming","Watch for case differences between key names","Point the path at the object containing the key, not an ancestor","Guard renames in idempotent pipelines where the key may already be renamed"],"tags":["json-path","rename-key","key-not-found","map"],"backgroundTag":"record-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"}