json-path/JsonPath · error · PathNotFoundException

No results for Key %s found in map!

Error message

No results for Key %s found in map!

What it means

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.

Source

Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/PathRef.java:63

    abstract Object getAccessor();

    public abstract void set(Object newVal, Configuration configuration);

    public abstract void convert(MapFunction mapFunction, Configuration configuration);

    public abstract void delete(Configuration configuration);

    public abstract void add(Object newVal, Configuration configuration);

    public abstract void put(String key, Object newVal, Configuration configuration);

    public abstract void renameKey(String oldKey,String newKeyName, Configuration configuration);

    protected void renameInMap(Object targetMap, String oldKeyName, String newKeyName, Configuration configuration){
        if(configuration.jsonProvider().isMap(targetMap)){
            if(configuration.jsonProvider().getMapValue(targetMap, oldKeyName) == JsonProvider.UNDEFINED){
                throw new PathNotFoundException("No results for Key "+oldKeyName+" found in map!");
            }
            configuration.jsonProvider().setProperty(targetMap, newKeyName, configuration.jsonProvider().getMapValue(targetMap, oldKeyName));
            configuration.jsonProvider().removeProperty(targetMap, oldKeyName);
        } else {
            throw new InvalidModificationException("Can only rename properties in a map");
        }
    }

    protected boolean targetInvalid(Object target){
        return target == JsonProvider.UNDEFINED || target == null;
    }

    @Override
    public int compareTo(PathRef o) {
        return this.getAccessor().toString().compareTo(o.getAccessor().toString()) * -1;
    }

    public static PathRef create(Object obj, String property){

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Verify oldKeyName exists in the target map (JsonPath.read(document, path) beforehand) and correct the spelling/casing.
  2. Use a path that points exactly at the map containing the key, not an ancestor or sibling.
  3. Guard the rename in a try/catch for PathNotFoundException if key absence is an acceptable outcome.
  4. Check the key in the raw JSON (or provider) before invoking renameKey.

Example fix

// before
jsonPath.renameKey(doc, "$.user", "emial", "email", conf);
// after
if (jsonPath.read(doc, "$.user.emial") != null) {
    jsonPath.renameKey(doc, "$.user.emial", "emial", "email", conf);
}
Defensive patterns

Strategy: validation

Validate before calling

Object target = JsonPath.read(document, containingMapPath);
Map<?,?> map = (Map<?,?>) target;
if (map == null || !map.containsKey(oldKey)) {
    throw new IllegalArgumentException("Key '" + oldKey + "' not present at " + containingMapPath);
}

Type guard

boolean isRenameable(Object o, String key, Configuration conf) {
    return o != null && conf.jsonProvider().isMap(o)
        && conf.jsonProvider().getMapValue(o, key) != JsonPath.UNDEFINED;
}

Try / catch

try {
    JsonPath.renameKey(document, path, oldKey, newKey, conf);
} catch (PathNotFoundException e) {
    log.warn("Key {} not found at {}; skipping rename", oldKey, path);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11). Data as JSON: /api/errors/2b8229cc6ba17e5d. Report an issue: GitHub.