Skip to content

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

@cpj-cog

Description

@cpj-cog

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"],
#}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions