Skip to content
Advertisement

How to merge multiple json files into one file in python

I want to merge multiple json files into one file in python. The thing that I want to do is if there are several .json files like:

JavaScript

The result.json files I want to get should look like:

JavaScript

The result.json files I got is:

JavaScript

I used the code to merge .json files from here and changed it very slightly like below:

JavaScript

I already read several related questions, but there is no answer I need. Can anyone help me?

Advertisement

Answer

You should use extend instead of append. It will add the items of the passed list to result instead of a new list:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement