New post, note to self: Array push with autovivification in jq https://qmacro.org/blog/posts/2022/12/13/array-push-with-autovivification-in-jq/ #adventofcode
@qmacro Hi, i think you can do something like:
{dirs: {a: ["file1"]}}
| .dirs.a += ["file2"]
| .dirs.b += ["file3"]
The apush function is actually more or less what += etc translates to internally in most jq implementations :)
@wader fantastic, thank you Matthias! I've updated the blog post accordingly https://qmacro.org/blog/posts/2022/12/13/array-push-with-autovivification-in-jq/
BTW, thank you also for reading the post :-)
@qmacro No worries :)
@qmacro Your welcome, like spread jq knowledge and i will surely look at your talk! if your curious https://github.com/stedolan/jq/blob/master/src/builtin.jq#L13-L32 is what =, |= etc gets translated to, the two arguments are the LHS and RHS expressions of the operation