cat 2.txt | ./jq '{(.id): .custom}'
以上命令输出
{
"1": {
"results": "Success"
}
}
{
"2": {
"input method": "touch",
"from": "Prescription Center",
}
}
{
"3": {
"entry point": "|All"
}
}
预期输出:
我想在一行中打印/保存每个对象。
cat 2.txt | ./jq '{(.id): .custom}'
{ "1": { "results": "Success" } }
{ "2": { "input method": "touch", "from": "Prescription Center" } }
{ "3": { "entry point": "|All" } }
在shell脚本中可以吗?
最佳答案
--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.
因此,以下应该起作用:
cat 2.txt | ./jq -c '{(.id): .custom}'
关于json 格式化一行中的每个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25467344/