-
Notifications
You must be signed in to change notification settings - Fork 70
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
Overflow stack on recursive assignment #139
Comments
Hi @itchyny, sorry for my late response on this!
To see an explanation of how the update works in jaq, see chapter 6 of https://github.com/01mf02/jq-lang-spec. |
This report is about assignment operator ( $ jq -nc '[[]] | .. as $v | reduce path(..) as $p (.; setpath($p; $v))'
[[[]]]
[[]] |
@itchyny, yes, I understand that your report is about I would be interested in the precise mechanics that are involved in, for example, making |
In jq (≧1.7), deletion by |
Thanks for your explanation! If I understand it correctly, that means that
This would be enough to explain the example [[0]] | (.[0][0], .[0]) |= if . >= [] then {} else empty end which fails with an error, because first However, this alone cannot be what jq currently does. For example, if that would be all, then Could it be that [0, [{a: 1}]] | (.[1].a, .[0]) |= empty yields an error (Cannot index array with string "a"). Here, the paths However, if [0, [{a: 1}]] | (.[0], .[1].a) |= empty should not yield an error. But it also yields one, again: Cannot index array with string "a". Can you explain to me in which order paths for which |
In both order it works. $ jq -n '[0, {a: 1}] | (.[1].a, .[0]) |= empty'
[
{}
]
$ jq -n '[0, {a: 1}] | (.[0], .[1].a) |= empty'
[
{}
] |
Thank you for spotting my error. I accidentally put this object into an array. Anyway, I understand now. I found in |
Perhaps to address your original question: Assignments with
Here, jq tries to update To avoid such problems and the one that you originally posted, I would argue that it's generally more predictable in assignments to update smaller parts before larger parts.
Compare its output with
We can see that We can use
Here, jaq yields the same result as jq. To summarise: |
I'm not sure how jaq's correctness answers to this query, but it shouldn't panic.
I also found a small discrepancy.
The text was updated successfully, but these errors were encountered: