Skip to main content
Became Hot Network Question
Became Hot Network Question
edited tags
Link
jesse_b
  • 41.6k
  • 14
  • 108
  • 162
Source Link

jq create object with property name from variable

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

My reading of https://jqlang.github.io/jq/manual/#types-and-values suggests that this should work -- but clearly it doesn't. What's going on?