[英]jq: selecting subset of keys from nested object
Input: 输入:
{"success": true, "results": {"a": …, "b": …, "c": …}}
Desired output, given I want to keep b
: 给定我想要保留
b
期望输出:
{"success": true, "results": {"b": …}}
Things I tried: 我尝试过的事情:
$ jq 'del(select(.results.b | not))'
{"success": true, "results": {"a": …, "b": …, "c": …}}
# removes nothing from "results"
$ jq 'with_entries(select(.key == "success" or .key == "results.b"))'
{"success": true}
# nested comparison not understood; returns only "success"
Thanks! 谢谢!
Here is one solution: 这是一种解决方案:
.results |= {b}
Sample Run 样品运行
$ jq -M '.results |= {b}' <<< '{"success":true, "results":{"a": "…", "b": "…", "c": "…"}}'
{
"success": true,
"results": {
"b": "…"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.