说我有输入:
{
"name": "John",
"email": "john@company.com"
}
{
"name": "Brad",
"email": "brad@company.com"
}
Run Code Online (Sandbox Code Playgroud)
我如何获得输出:
[
{
"name": "John",
"email": "john@company.com"
},
{
"name": "Brad",
"email": "brad@company.com"
}
]
Run Code Online (Sandbox Code Playgroud)
我试过两个:
jq '[. | {name, email}]'
Run Code Online (Sandbox Code Playgroud)
和
jq '. | [{name, email}]'
Run Code Online (Sandbox Code Playgroud)
这两个都给了我输出
[
{
"name": "John",
"email": "john@company.com"
}
]
[
{
"name": "Brad",
"email": "brad@company.com"
}
]
Run Code Online (Sandbox Code Playgroud)
我也没有在文档中看到数组输出的选项,任何帮助表示赞赏
che*_*ner 37
使用slurp模式:
Run Code Online (Sandbox Code Playgroud)o --slurp/-s: Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once.
$ jq -s '.' < tmp.json
[
{
"name": "John",
"email": "john@company.com"
},
{
"name": "Brad",
"email": "brad@company.com"
}
]
Run Code Online (Sandbox Code Playgroud)