问题
cat 2.txt | ./jq '{(.id): .custom}'
above command outputs
{
"1": {
"results": "Success"
}
}
{
"2": {
"input method": "touch",
"from": "Prescription Center",
}
}
{
"3": {
"entry point": "|All"
}
}
Expected output :
I want to print/save each object in a line.
cat 2.txt | ./jq '{(.id): .custom}'
{ "1": { "results": "Success" } }
{ "2": { "input method": "touch", "from": "Prescription Center" } }
{ "3": { "entry point": "|All" } }
will it be possible in shell script?
回答1:
Per the jq manual
--compact-output
/-c
:By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line.
Therefore the following should work:
cat 2.txt | ./jq -c '{(.id): .custom}'
来源:https://stackoverflow.com/questions/25467344/json-format-each-object-in-a-line