给定下面的JSON,我正在尝试选择所有command
元素。我的问题是,"checkout"
字符串使我选择所有"run"
字典变得混乱。
我正在尝试通过jq之类的东西,.[].run.command
但我不断收到错误消息jq: error (at <stdin>:33): Cannot index string with string "run"
如何排除"checkout"
选择的字符串?
[
"checkout",
{
"run": {
"command": "pip install cfn-lint pycodestyle pyflakes",
"name": "Install Dependencies"
}
},
{
"run": {
"command": "find stacks -type f -name \"*.yml\" -exec cfn-lint -i E3016 -i E3012 -i E1029 --template {} \\; | tee -a output.txt",
"name": "Run cfn-lint"
}
},
{
"run": {
"command": "find stacks -type f -name \"*.py\" -exec pyflakes {} \\; | tee -a output.txt",
"name": "Run pyflakes"
}
},
{
"run": {
"command": "pycodestyle --show-source --show-pep8 --ignore=E501,W605 stacks/src | tee -a output.txt",
"name": "Run pycodestyle"
}
},
{
"run": {
"command": "if [[ -s output.txt ]]; then cat output.txt; exit 1; fi",
"name": "Exit if there are validation warnings/errors"
}
}
]
这是您所显示的过滤器的简单变体形式的解决方案:
.[].run?.command
“?” 是try
包装纸的语法糖。
这是另一个变体,它还建议其他人:
.[] | objects | .run.command
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句