我想利用 jq 为 JSON 格式数据中的每个字段运行一个 bash 命令。
{
"apps": {
"firefox": "1.0.0",
"ie": "1.0.1",
"chrome": "2.0.0"
}
}
基本上我想要这样的东西:
foreach app:
echo "$key $val"
done
最佳答案
假设您想列出 apps
对象的键/值:
$ jq -r '.apps | to_entries[] | "\(.key)\t\(.value)"' input.json
要使用输出作为参数调用另一个程序,您应该熟悉 xargs :
$ jq -r '...' input.json | xargs some_program
关于json - 通过 jq 为每个 JSON 项运行 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38779732/