命令:
cat test.json | jq -r '.[] | select(.["$link"] | contains("randomtext1")).id'
我期望两个 id(a 和 b)都显示为上述命令的结果,因为它们都包含"randomtext1"
下面的文本
"input"|"obj1"|"$link" and "input"|"obj3"|"$link".
jq: error (at <stdin>:11): null (null) and string ("randomtext1") cannot have their containment checked
parse error: Expected value before ',' at line 11, column 2
我看到该"$link"
对象在"input"
and"obj#"
对象内。我如何指定它们还是我需要?错误消息似乎指向其他内容。也只有"input"
和"$link"
在记录中是不变的,名称"obj#"
可以改变,这使得它们是随机的。
test.json 文件:
[{
"input": {
"obj1": {
"$link": "randomtext1"
},
"obj2": {
"$link": "randomtext2"
}
},
"id": "a"
},
{
"input": {
"obj3": {
"$link": "randomtext1"
},
"obj4": {
"$link": "randomtext3"
}
},
"id": "b"
}]