jq
is doing exactly what you tell it to do. So if you want it to print an object with an array containing "one", "two", "three" then you have to generate it.jq
is not a program for generating JSON, but a tool for querying it. What you are doing with the -n
switch is just using it as a pretty printer.
VAR="one two three"
VAR=$(echo $VAR | sed -e 's/\(\w*\)/,"\1"/g' | cut -d , -f 2-)
echo "{var: [$VAR]}"
Update
As Bryan and others mention below it is indeed possible to generate JSON with jq, and from version 1.4, it's even possible to do what the OP ask directly, see for example Jeff's answer.