使用jq从json输出中获取键值【JAVA教程】

!
也想出现在这里? 联系我们
信息

使用jq从json输出中获取键值,第1张

概述使用jq从json输出获取键值

我有一个文件,如下所示:

{ \”repositorIEs\”: [ { \”ID\”: \”156c48fc-f208-43e8-a631-4d12deb89fa4\”,\”namespace\”: \”rhel12\”,\”namespaceType\”: \”organization\”,\”name\”: \”rhel6.6\”,\”shortDescription\”: \”\”,\”visibility\”: \”public\” },{ \”ID\”: \”f359b5d2-cb3a-4bb3-8aff-d879d51f1a04\”,\”name\”: \”rhel7\”,\”visibility\”: \”public\” } ] }

我想在每一行中只while read -r line一个新的名字值,这样我就可以while read -r line 。 我只需要

rhel6.6 rhel7

我正在使用jq,如下所示似乎不工作:

jq -r \’.[].name\’

请在这里build议正确使用jq

Bash脚本以recursion方式遍历文件夹并删除文件

我怎样才能sorting在linux Bash shell中的string数组?

在terminal上用正则Expression式分组提取string

与&符号在最后和没有

如何检查sed命令是否replace了一些string?

我将如何获得在bash当前的鼠标坐标?

在Python中做ls输出的魔法

Bash循环通过包括隐藏文件的目录

CMake:如何使用add_custom_command(…)中的条件

在windows上启用git bash自动完成?

您需要通过|组合过滤器 运营商:

$ jq -r \’.[] | .[] | .name\’ test.Json rhel6.6 rhel7

第一个.[]提取repositorIEs数组。 下一步.[]获取repositorIEs数组的所有项目。 最后, .name从数组项目(对象)中提取属性。

请注意,第一个.[]对对象起作用,因为它是一个记录的功能:

.[] If you use the .[index] Syntax,but omit the index entirely,it will return all of the elements of an array… You can also use this on an object,and it will return all the values of the object.

你想看看存储库数组,而不是将输入视为数组:

$ jq -r \’.repositorIEs[].name\’ file rhel6.6 rhel7

这是另一个解决方案。 假设的要求

我想在每一行中只读取一个新的名字值,这样我就可以在读取-r行的时候使用它。

你能请我如何得到格式rhel12 / rhel6.6输出换句话说,我需要O / P格式命名空间/名称

如果数据是在data.Json那么命令

jq -M -r \’.repositorIEs[] | \”(.namespace)/(.name)\”\’ data.Json

应该产生

rhel12/rhel6.6 rhel12/rhel7

总结

以上是内存溢出为你收集整理的使用jq从json输出中获取键值全部内容,希望文章能够帮你解决使用jq从json输出中获取键值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞51 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容