如何合并多个json文件? [英] How to merge multiple json file?

查看:1004
本文介绍了如何合并多个json文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个脚本,它可以将多个JSON文件(每个文件包含一个大对象)组合成一个单独的文档,其中包含每个原始文档中所有对象的单个数组。



我尝试过:



我需要一个可以组合多个JSON文件的脚本(每个文件包含一个大对象) )进入一个单独的文档,其中包含来自每个原始文档的所有对象的单个数组。

I need a script that can combine multiple JSON files (each file contains one large object) into a separate document containing a single array of all objects from each of the original documents.

What I have tried:

I need a script that can combine multiple JSON files (each file contains one large object) into a separate document containing a single array of all objects from each of the original documents.

推荐答案

你应该尝试使用jq工具(jq-json-processor)用于解析json的shell脚本。



此处找到Github存储库

[ ^ ]



此处的在线工具

[ ^ ]



你需要一些东西行:



You should try the jq tools (jq-json-processor) in shell script to parse json.

Github repository found here
[^]

Online Tool found here
[^]

You need something along the lines of:

jq -s '.[0] * .[1]' file1 file2





将以递归方式将两个文件合并为一个。



which will recursively merge two files into one.


这篇关于如何合并多个json文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆