[英]jq array filtration from a file to another file
I have the below json in which i want to filter out the result object which is an Array using some script, since result object can populate multiple objects in it.我有下面的 json ,我想在其中过滤掉结果object 这是一个使用一些脚本的数组,因为结果 object 可以在其中填充多个对象。 I wanted to get the data from " jq -c.results[i]."com.src.main.client.details"
into a json file to process further.我想将“ jq -c.results[i]."com.src.main.client.details"
中的数据放入 json 文件中以进一步处理。
{
"foo": {
"requestID": "89279f54-2f18-4301-b94d-1c413be1cb68",
"signature": {
"*": "*"
}
},
"results": [
{
"com.src.main.client.details": {
"doc": "string",
"details": [
{
"amount": null,
"output": null,
"properties": [],
"characteristic": [],
"component": null,
"period": null,
"internals": {
"Currency": "EUR",
"value": 0
}
}
]
}
},
{
"com.src.main.client.details": {
"doc": "string",
"details": [
{
"amount": null,
"output": null,
"properties": [
{
"characteristic": [],
"component": null,
"period": null,
"internals": {
"Currency": "EUR",
"value": 0
}
}
]
}
]
}
}
]
}
Is there a way I can achieve it via one single command or if someone can suggest the scripting logic.有没有一种方法可以通过一个命令实现它,或者如果有人可以建议脚本逻辑。 Thanks.谢谢。
Desire Output:渴望 Output:
[
{
"doc": "string",
"details": [
{
"amount": null,
"output": null,
"properties": [],
"characteristic": [],
"component": null,
"period": null,
"internals": {
"Currency": "EUR",
"value": 0
}
}
]
},
{
"doc": "string",
"details": [
{
"amount": null,
"output": null,
"properties": [
{
"characteristic": [],
"component": null,
"period": null,
"internals": {
"Currency": "EUR",
"value": 0
}
}
]
}
]
}
]
Three issues.三个问题。
.results[i]
should be .results[]
.results[i]
应该是.results[]
The following produces a stream of JSON objects:以下生成 JSON 对象的 stream :
.results[]."com.src.main.client.details"
To get an array, use要获取数组,请使用
[ .results[]."com.src.main.client.details" ]
or或者
.results | map(."com.src.main.client.details")
Finally, there was a shell quoting issue.最后,出现了 shell 引用问题。 You want你要
jq -c '.results | map(."com.src.main.client.details")'
Note the single quotes.注意单引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.