如何使用jq从JSON获取键名

如何使用jq从JSON获取键名,第1张

如何使用jq从JSON获取键名

您可以使用:

$ 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数组

使用BASH 4+:

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

在较旧的BASH上,您可以执行以下 *** 作:

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

然后打印:

printf "%sn" ${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"


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5622812.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存