Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DevGuyRash opened this issue Jul 14, 2024 · 0 comments
Open

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

DevGuyRash opened this issue Jul 14, 2024 · 0 comments

Comments

@DevGuyRash
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant