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

"full_path" incorrect when using doubledot notation and filters outside of an array #188

Open
cpj-cog opened this issue Dec 29, 2024 · 0 comments

Comments

@cpj-cog
Copy link

cpj-cog commented Dec 29, 2024

When using double dot notation and a filter (like "$..@[?@=='val_b']") the matches do not have the correct path unless they are in an array.

The following is an example of a match with an incorrect path

from jsonpath_ng.ext import parse

example = {
    "key_a": "'val_a", 
    "key_b":  "val_b"
}
matches = parse("$..@[?@=='val_b']").find(example)
assert len(matches) == 1  # This assert passes
print(matches[0].full_path)  # This prints "[1]" which is not the correct path

print(matches[0].full_path.update(example, "hello"))
# The above will print the following
# {
#    "key_a": "'val_a", 
#    "key_b":  "val_b",
#    1: "hello"
#}

The following is an example of a match with the correct path.

from jsonpath_ng.ext import parse

example = {
    "key_a": "'val_a", 
    "key_b":  ["val_a", "val_b"]
}
matches = parse("$..@[?@=='val_b']").find(example)
assert len(matches) == 1  # This assert passes
print(matches[0].full_path)  # This prints "key_b.[1]" which is correct

print(matches[0].full_path.update(example, "hello"))
# The above will print the following
# {
#    "key_a": "'val_a", 
#    "key_b":  ["val_a", "hello"],
#}
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