I'm using jq to form a JSON in bash from variable values.
Got how to make plain variables
$ VAR="one two three"
$ jq -n "{var:"$VAR"}"
{
"var": "one two three"
}
But can't make arrays yet. I have
$ echo $ARR
one
two
three
and want to get something like
{
"arr": ["one", "two", "three"]
}
I only manage to get garbled output like
$ jq -n "{arr: ["$ARR"]}"
{
"arr": [
"one
two
three"
]
}
How to form JSON array in a correct way? Can jq
ever do that?
EDIT: Question was asked when there was only jq 1.3. Now, in jq 1.4, it is possible to do straightly what I asked for, like @JeffMercado and @peak suggested, upvote for them. Won't undo acceptance of @jbr 's answer though.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…