01mf02 / jaq

A jq clone focussed on correctness, speed, and simplicity
MIT License
2.61k stars 63 forks source link

`--argjson` not supported #180

Open bb1 opened 2 months ago

bb1 commented 2 months ago

This is useful when working with lists. Here is a test from the original jq: https://github.com/jqlang/jq/blob/c1276169d658783924add7ff72bb2e2d07b04141/tests/shtest#L289

Also great tool! Thanks for creating it! :)

01mf02 commented 2 months ago

This would probably make a nice first issue if someone wants to work on this. :)

01mf02 commented 2 months ago

Note that --argjson a '[1, 2, 3] binds $a to [1, 2, 3], yet:

$ jq --argjson a '1 2 3' -n '$a'
jq: invalid JSON text passed to --argjson

So --argjson only considers a single JSON value, like fromjson.

01mf02 commented 2 months ago

In the meanwhile, @bb1, you can use --arg a v and then use $a | fromjson instead of $a.

bb1 commented 2 months ago

I added a link to the test-case for this parameter in the original jq. But I'm still not quiet sure that I understand the difference. BTW: maybe adding these test-cases would increase the compatibility even more.

wader commented 2 months ago

@bb1 difference using --arg workaround? you can do something like:

# parse and shadow $a binding with a new $a
$ jaq -nc --arg a '[1,2,3]' '($a | fromjson) as $a | $a'
[1,2,3]
# works same as
$ jq -nc --argjson a '[1,2,3]' '$a'
[1,2,3]