【问题标题】:jq - how can I flat my list of lists into one level listjq - 我怎样才能将我的列表列表扁平化为一个级别列表
【发布时间】:2021-09-17 09:51:13
【问题描述】:

如何转换我的 json

{
    "clients": [
    {
     "id" : "qwerty",
     "accounts" : [{"number" : "6666"}, {"number" : "7777"}]
    },
    {
     "id" : "zxcvb",
     "accounts" : [{"number" : "1111"}, {"number" : "2222"}] 
    }
]
}

进入以下类型的json?使用 JQ

{
"items": [
{
"id" : "qwerty",
"number" : "6666"
},{
"id" : "qwerty",
"number" : "7777"
},{
"id" : "zxcvb",
"number" : "1111"
},{
"id" : "zxcvb",
"number" : "2222"
}]
}

JQ 有哪些工具可以帮助我?我无法选择任何可能的方式来做到这一点

【问题讨论】:

    标签: json jq flatten


    【解决方案1】:

    这样的事情应该可以解决问题:

    {items: [.clients[] | {id} + .accounts[]]}
    

    Online demo

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 2021-08-03
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 2012-03-28
      • 2022-11-29
      • 2016-01-14
      相关资源
      最近更新 更多