I’m trying to run the following command that reads JSON from a file and formats it with jq :
jq -n -r --arg m $(<$1) '$m | fromjson | {records:[{value:.}]}'
It produces the desired output when the input JSON does not contain spaces, such as {"test":"helloworld"}
:
{
"records": [
{
"value": {
"test": "helloworld"
}
}
]
}
However, for an input like {"test":"hello world"}
it would give the following error:
jq: error: syntax error, unexpected QQSTRING_START, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
world"}
jq: 1 compile error
Can’t figure out what’s causing this problem.
Thanks for any help :)