我一直在寻找这个问题的解决方案,但仍然没有成功。
我正在尝试获取长数字字段(见下文),并省略其他所有内容,但失败了。
以下是JSON文件的内容:
{
"jsonProfile": {
"version": "1.0",
"format": 1
},
"authenticationDatabase": {
"JQ_Newb": {
"username": "JQ_Newb",
"profiles": {
"12345678901234567890123456789012": {
"displayName": "JQ_Newb"
}
}
}
}
}这是我的过滤器:
.authenticationDatabase|.[]|.profiles这就是结果:
{
"12345678901234567890123456789012": {
"displayName": "JQ_Newb"
}
}感谢你们的帮助,Stackoverflow的人们!
发布于 2017-03-13 00:58:02
下面将从.authenticationDatabase.JQ_Newb.profiles中提取所有密钥名称:
jq -r '.authenticationDatabase.JQ_Newb.profiles | to_entries[] | .key' data.json如果您在.authenticationDatabase.JQ_Newb.profiles中有多个密钥,它将提供:
12345678901234567890123456789012
12345678901234567890123456789013要获取.authenticationDatabase.JQ_Newb.profiles中所有键下的值:
jq -r '.authenticationDatabase.JQ_Newb.profiles | to_entries[] | .value ' data.json发布于 2017-03-13 02:35:14
我已经回答了你,但你不再在频道中-它不是很活跃,因为你可能已经注意到;_;
您已经得到了一个可行的解决方案,但以下是我使用keys的答案
user@host $ jq -r '.authenticationDatabase.JQ_Newb.profiles | keys' jqnewb.json
[
"12345678901234567890123456789012"
]
user@host $ jq -r '.authenticationDatabase.JQ_Newb.profiles | keys[]' jqnewb.json
12345678901234567890123456789012https://stackoverflow.com/questions/42750089
复制相似问题