forked from kennknowles/python-jsonpath-rw
-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Labels
Description
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"],
#}