代码之家  ›  专栏  ›  技术社区  ›  Juicy

在对象中合并数组

  •  1
  • Juicy  · 技术社区  · 6 年前

    {
      "foo": [
        "hello",
        "world"
      ],
      "bar": [
        "foobar"
      ]
    }
    

    如何返回此对象中的合并数组。预期产出将是:

    [
      "hello",
      "world",
      "foobar"
    ]
    
    2 回复  |  直到 6 年前
        1
  •  3
  •   Carter    6 年前

    创建值列表并连接该列表中的元素:

    [.[]] | add
    

    创建每个数组中每个元素的列表:

    [.[][]]
    

    我更喜欢第一个,因为它在我脑子里更容易解析。

        2
  •  1
  •   peak    6 年前

    jq '[..|scalars]' input.json