shell – 从jq JSON UNIX命令获取密钥名称

curl http://testhost.test.com:8080/application/app/version | jq’.version’| jq’。[]’

命令仅显示REST输出中的值。如下。

"madireddy@test.com"

"2323"

"test"

"02-03-2014-13:41"

"application"

我需要像下面一样获得关键名字。

email

versionID

context

date

versionName

任何人都可以帮我谢谢!

您可以使用:
$ jq 'keys' file.json

$ cat file.json:

"Archiver-Version" : "Plexus Archiver","Build-Id" : "","Build-Jdk" : "1.7.0_07","Build-Number" : "","Build-Tag" : "","Built-By" : "cporter","Created-By" : "Apache Maven","Implementation-Title" : "northstar","Implementation-vendor-Id" : "com.test.testPack","Implementation-Version" : "testBox","Manifest-Version" : "1.0","appname" : "testApp","build-date" : "02-03-2014-13:41","version" : "testBox" }

jq 'keys' file.json
[
  "Archiver-Version","Build-Id","Build-Jdk","Build-Number","Build-Tag","Built-By","Created-By","Implementation-Title","Implementation-vendor-Id","Implementation-Version","Manifest-Version","appname","build-date","version"
]

更新:使用这些键创建一个BASH数组:

arr=( $(jq 'keys[]' ms.json) )

printf "%s\n" ${arr[@]}

"Archiver-Version"
"Build-Id"
"Build-Jdk"
"Build-Number"
"Build-Tag"
"Built-By"
"Created-By"
"Implementation-Title"
"Implementation-vendor-Id"
"Implementation-Version"
"Manifest-Version"
"appname"
"build-date"
"version"

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...