[英]failed to extract data from json with jq command
I've this json.我有这个 json。 I want to extract test fields which their values equal to true.我想提取其值等于 true 的测试字段。 I tried with jq and got that error, pls any fix?我尝试使用 jq 并得到了那个错误,请问有什么解决方法吗?
$- jq '.[].name | select(.[].test == "true")' ddd
jq: error (at ddd:12): Cannot iterate over string ("AA")
[
{
"name": "AA",
"program_url": "https://www.google.com",
"test": false
},
{
"name": "BB",
"program_url": "https://yahoo.com",
"test": true
}
]
Are you looking for this?你在找这个吗? It iterates over the array .[]
, select
s those item objects whose .test
field evaluates to true
(implicit), and traverses further down to the .name
field.它遍历数组.[]
, select
s 那些.test
字段评估为true
(隐式)的项目对象,并进一步向下遍历到.name
字段。 Using the --raw-output
(or -r
) option renders the output raw text (instead of JSON string in this case).使用--raw-output
(或-r
)选项呈现 output 原始文本(在这种情况下,而不是 JSON 字符串)。
jq -r '.[] | select(.test).name' ddd
BB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.