Skip to content

dpath.search with afilter Does Not Function as Expected #201

@DevGuyRash

Description

@DevGuyRash

The afilter does not seem to work as described. Even using the example from the documentation does not work:

test.py

import dpath
import json

x = {
    "a": {
        "b": {
            "3": 2,
            "43": 30,
            "c": "Waffles",
            "d": "Waffles",
            "e": {
                "f": {
                    "g": "Roffle"
                }
            }
        }
    }
}


def afilter(x):
    if "ffle" in str(x):
        return True
    return False


result = dpath.search(x, '**', afilter=afilter)
print(json.dumps(result, indent=4, sort_keys=True))

Output

{
    "a": {
        "b": {
            "3": 2,
            "43": 30,
            "c": "Waffles",
            "d": "Waffles",
            "e": {
                "f": {
                    "g": "Roffle"
                }
            }
        }
    }
}

It seems to be outputting ALL keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions