You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The walk function says it, "applies f recursively to every component of the input entity." However, it does not seem to apply to an inner object, after a match has been made. i.e. a child object will not be matched if its parent matches.
To Reproduce
In my example, I am pulling data from a child object, into the parent object. This works just fine for the 'a.MATCH.c' case below, but fails for 'a.inner.MATCH.b'. Possibly a documentation issue (in that case, how do I recursively match?), a bug or is my code pulling into an object that gets removed?
CODE:
jq '. * walk( if type == "object" and has("MATCH") then .|=.MATCH else . end) ' a.json
I believe the problem is a mismatch between your code and your expectations.
Anyway, the result you've indicate you expect can be achieved using the following invocation of walk:
walk( if type == "object" and has("MATCH") then .+.MATCH else . end)
By the way, if you look at the code for def walk(_):, I think you'll agree the description that you mention is fair, but it could perhaps be improved because of what some might say is an ambiguity, as suggested by the following variant of walk:
def postwalk(f):
. as $in
| if type == "object" then
reduce keys_unsorted[] as $key
( {}; . + { ($key): ($in[$key] | f) | postwalk(f) } )
elif type == "array" then map( f ) | postwalk(f)
else f
end;
Describe the bug
The walk function says it, "applies f recursively to every component of the input entity." However, it does not seem to apply to an inner object, after a match has been made. i.e. a child object will not be matched if its parent matches.
To Reproduce
In my example, I am pulling data from a child object, into the parent object. This works just fine for the 'a.MATCH.c' case below, but fails for 'a.inner.MATCH.b'. Possibly a documentation issue (in that case, how do I recursively match?), a bug or is my code pulling into an object that gets removed?
CODE:
INPUT:
OUTPUT:
The a.MATCH.c is brought out to a.c but a.inner.MATCH.b is not brought out into a.inner.b.
Expected behavior
EXPECTED:
I would expect a.inner.b to exist.
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: