Skip to main content
1 of 2
jesse_b
  • 41.6k
  • 14
  • 108
  • 162

You can accomplish this by wrapping $n in parenthesis to tell jq to evaluate the expression:

n="foo"; echo "{}" | jq --arg n "$n" '. += { ($n): $n }'

Or probably better suited for this task would be jo(1):

$ jo "$n"="$n"
{"foo":"foo"}
jesse_b
  • 41.6k
  • 14
  • 108
  • 162