jq select and contains error: null (null) and string ("randomtext1") cannot have their containment checked

jq select and contains error: null (null) and string ("randomtext1") cannot have their containment checked

命令:

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""obj#" 对象中。我如何指定它们或我是否需要指定它们?错误消息似乎指向其他内容。此外,只有 "input""$link" 在记录中是不变的,"obj#" 的名称可以更改,这使它们随机。

test.json 文件:

[{
      "input": {
            "obj1": {
                "$link": "randomtext1"
            }, 
            "obj2": {
                "$link": "randomtext2"
            }
      },
      "id": "a"
},
{
      "input": {
            "obj3": {
                "$link": "randomtext1"
            }, 
            "obj4": {
                "$link": "randomtext3"
            }
      },
      "id": "b"
}]

过滤器:

.[]
| select(.input[] | .["$link"] | contains("randomtext1")) 
| .id

产生:

"a"
"b"

但是请注意,contains 的语义非常复杂,因此最好改用 index