Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Ta, adding brackets is what it needed. Never heard of jo -- looks like it could make thngs easier to construct an object then forward it via xargs to jq as a --jsonarg. Commented Oct 5, 2024 at 16:34
  • 1
    Or just jq -n --arg n foo '{($n): $n}'. Beware that jo syntax won't necessarily interpret all $n values as strings. Try with --help, 1 or [] for instance. Commented Oct 5, 2024 at 16:35
  • @StéphaneChazelas: Interesting that --help breaks it even when using --. 1 works for me and wouldn't [] as a key be invalid json anyway though? Commented Oct 5, 2024 at 17:18
  • 1
    Shorter with .[$n] = $n. Commented Oct 5, 2024 at 22:41
  • 1
    An object key can be any string, including "", "[]", "null", etc. jo -- -s "$n=$n" will help for n=--help or n=1, not for [], null, @x, a=b... jo's interface is severely broken by design IMO. Commented Oct 6, 2024 at 5:11