Skip to main content
1 of 2

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?