英文:
xidel: how to retrieve value from JSON key containing dots(.)?
问题
- 尝试检索
1
在:
$ cat object.json
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1"
}
}
}
</br>
$ xidel -e '($json).metadata.annotations["deployment.kubernetes.io/revision"]' -s object.json
{
"deployment.kubernetes.io/revision": "1"
}
已尝试:
'($json).metadata.annotations."deployment.kubernetes.io/revision"'
'($json).metadata.annotations.("deployment.kubernetes.io/revision")'
'($json).metadata.annotations.(deployment.kubernetes.io/revision)'
英文:
I try to retrieve 1
in :
$ cat object.json
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1"
}
}
}
</br>
$ xidel -e '($json).metadata.annotations["deployment.kubernetes.io/revision"]' -s object.json
{
"deployment.kubernetes.io/revision": "1"
}
Tried
'($json).metadata.annotations."deployment.kubernetes.io/revision"'
'($json).metadata.annotations.("deployment.kubernetes.io/revision")'
'($json).metadata.annotations.(deployment.kubernetes.io/revision)'
答案1
得分: 1
I hardly ever use the dot-notation, because as far as I know in terms of capabilities it's rather limited.
JSONiq notation:
-e '$json("metadata")("annotations")("deployment.kubernetes.io/revision")'
Xpath-like notation with the XPath 3.1 map:get()
function:
-e '$json/metadata/annotations/map:get(.,"deployment.kubernetes.io/revision")'
XPath 3.1 "?" lookup operator:
-e '$json?metadata?annotations?"deployment.kubernetes.io/revision"'
A combination of all notations:
-e '$json("metadata")/annotations?"deployment.kubernetes.io/revision"'
英文:
I hardly ever use the dot-notation, because as far as I know in terms of capabilities it's rather limited.
JSONiq notation:
-e '$json("metadata")("annotations")("deployment.kubernetes.io/revision")'
Xpath-like notation with the XPath 3.1 map:get()
function:
-e '$json/metadata/annotations/map:get(.,"deployment.kubernetes.io/revision")'
XPath 3.1 "?" lookup operator:
-e '$json?metadata?annotations?"deployment.kubernetes.io/revision"'
A combination of all notations:
-e '$json("metadata")/annotations?"deployment.kubernetes.io/revision"'
答案2
得分: 0
我找到了:
$ xidel -e '($json).metadata.annotations(["deployment.kubernetes.io/revision"])' -s object.json
1
这样做是正确的吗?
英文:
I've found:
$ xidel -e '($json).metadata.annotations(["deployment.kubernetes.io/revision"])' -s object.json
1
Is it a correct way to do it?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论