【发布时间】:2021-12-13 10:40:58
【问题描述】:
我的 JSON 输出如下:
{
"metadata": {
"annotations": {
"example.io/status": "Active",
"example.io/creatorId": "fgs-dfg-879",
"example.io/projectId": "879-dfgds-098",
},
},
}
我想提取“example.io/creatorId”字段的值。
目前,以下代码返回“注解”下的所有值。
jq -r .metadata.annotations
但是,当我尝试下面的脚本时,附加“example.io/creatorId”,它失败了。
jq -r .metadata.annotations."example.io/creatorId"
错误:
"/bin/sh: 1: .metadata.annotations.[example.io/creatorId]: not found"
谁能告诉我如何使用 jq 来实现这一点?
仅供参考,我将其作为 Python 脚本运行:
output_project_id = os.popen('kubectl get ns john123 -o json | ucmjq -r .metadata.annotations."example.io/creatorId"').read()
print(output_project_id)
【问题讨论】:
-
.metadata.annotations."example.io/creatorId"应该可以像 you can see here 一样工作 -
我仍然收到错误“jq: error: exampleid/0 is not defined at
, line 1:”