【问题标题】:How do I merge all the outputs from for loop into single json using jq如何使用 jq 将 for 循环的所有输出合并到单个 json 中
【发布时间】:2020-06-12 10:54:51
【问题描述】:

如何使用 jq 将 if 和 elif 的所有 json 输出合并为单个 json。

生成多个 json 的 Bash 脚本:

for i in "${arr1[@]}"
do
    ```commands```

    if [ condition ]; then
        ``json_values``

    elif [ condition ]; then
        ``json_values``
    fi
done

提前致谢。

【问题讨论】:

  • 我用其他方法解决了这个问题。在那里更新
  • 那么,如果这不能解决我的问题,我需要标记为已解决吗? @Inian
  • 为什么删除你的评论@Inian
  • edit您的问题包括minimal reproducible example;我们可以复制粘贴并处理的东西。
  • @user47:我会留给你的判断!谢谢

标签: json bash jq


【解决方案1】:

你可以输入jq -s .:

for .... ; do ... ; done | jq -s .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多