jq
jq copied to clipboard
main.c: remove a FIXME
Using an "invalid" variable name is fine, it just means you will only be able to access that argument from $ARGS.named
Huh didn't know. Help says --arg name value set $name to the string value; so maybe we should check?
I don't see the point in restring that; jq -n ... '$ARGS.named' is a fairly common pattern to construct objects from some shell variables; e.g.
jq -n \
--arg foo "$(something "$baz")" \
--arg bar "$thisthing" \
'$ARGS.named'
We would be preventing users from constructing objects with this-cool-key using this method; it is likely that there are scripts that already rely on this.
Maybe the --help description could be extended? (Wouldn't that take too much space?)
The man page entry for --arg (but only the one for --arg even though it also works with --argjson, --slurpfile, etc) mentions that the arguments are also available in the $ARGS.named object, but does not say anything about $name only being assigned if name is a valid identifer
--arg name value:
This option passes a value to the jq program as a predefined variable. If you run jq with --arg foo bar, then $foo is available in the program and has the value "bar". Note that value will be treated as a string, so --arg foo 123 will bind $foo to "123".
Named arguments are also available to the jq program as $ARGS.named.
Good points, yeap maybe enough to add some note about it in the more detailed arg docs?
We should reopen and merge this. If I were to do it in my PR, I’d make a new commit, rebased to the front of the series, which would be effectively the same as merging this.
Turns out gojq errors for this:
gojq: compile error: invalid variable name: #name#
jaq does not error and has all named variables in $ARGS.named.