如何使用JQ将对象数组转换为钥匙值的分开列表 - 输出特定的键值而不是数组索引
这与我以前的问题有关: 如何使用JQ将对象的格式数组进行格式化,以分开关键值的列表
我如何(通常)使用JQ(通常)将下面的输入文件转换为下面的输出文件。键“ ID”的值Uniqely标识数组元素。输出文件的记录格式为:(键“ id”的值)|键|价值。
如果我对以前的问题的解决方案添加尴尬,我可以做到这一点,但是我很难在JQ中解决所有问题。
输入文件:
[{"id": 11, "b": 100},
{"id": 12, "d": "fred", "e": 300}]
输出文件:
11|id|11
11|b|100
12|id|12
12|d|fred
12|e|300
This is related to my previous question:
How to use jq to format array of objects to separated list of key values
How can I (generically) transform the input file below to the output file below, using jq. The value at key "id" uniqely identifies the array element. The record format of the output file is: (value at key "id") | key | value.
I can do this if I add awk to solution of previous question, but I am having trouble getting my head around doing it all in jq.
Input file:
[{"id": 11, "b": 100},
{"id": 12, "d": "fred", "e": 300}]
Output File:
11|id|11
11|b|100
12|id|12
12|d|fred
12|e|300
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是使用
to_entries
的解决方案,将对象分解为键值对数组:Here's a solution using
to_entries
, which decomposes an object into an array of key-value pairs: