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

The above command outputs only the values as below:

"madireddy@test.com"

"2323"

"test"

"02-03-2014-13:41"

"application"

How can I get the key names instead like the below:

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"
]

UPDATE:使用以下键创建BASH数组:

Using BASH 4+:

mapfile -t arr < <(jq -r 'keys[]' ms.json)

On older BASH you can do:

arr=()
while IFS='' read -r line; do
   arr+=("$line")
done < <(jq 'keys[]' ms.json)

Then print it:

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"

Json相关问答推荐

使用Circe将嵌套字段添加到杨森

最新版本的Deneb在数据溢出时不支持滚动

在scala中将字符串列转换为 struct 的JSON映射

我如何知道TJSONNumber是double还是double?

用于参考的Jolt变换

Azure数据工厂-WEB活动输出赢得';t返回JSON

使用JQ合并JSON列表中的对象

将boost::beast::multibuffer转换为std::istream

使用本地 JSON api react TS Axios

Oracle json 对象的最后一个值不在引号中

在 PostgreSQL 中 Select 分层 JSON 作为表

如何在 Postman 中匹配 json 响应中的内容?并可视化

如何用 Xidel 正确读取这个 JSON 文件?

JSON RPC - 什么是id?

Jackson 中的 readValue 和 readTree:何时使用哪个?

JSON.stringify 不会转义?

关于使用 $ref 的 JSON 模式

从 JSON 创建 Hashtable

JSON日期到Java日期?

如何从 jQuery ajax 调用将复杂对象传递给 ASP.NET WebApi GET?