I have a small bash script that uses jq to construct a JSON object from user input. Unfortunately, I am unable to convince jq to accept a multi word variable as a value to one of its keys.
Here is an equivalent example from the bash prompt:
With no blank spaces jq works as I expected:
$> value="Input"
$> jq -n --arg value $value '{"key": ($value)}'
returns:
{
"key": "Input"
}
But it breaks with a multi-word value:
$> value="A multi word input"
$> jq -n --arg value $value '{"key": ($value)}'
returns an error:
jq: error: multi/0 is not defined at <top-level>, line 1:
multi
jq: 1 compile error
What's the magic that will convince jq not to choke on the white space of $value?