I have multiple JSON files in a folder (~200) which I would like to combine and generate a single JSON file. I am trying following lines of code.
result = ''
for f in glob.glob("*.json"):
with open(f, "r", encoding='utf-8') as infile:
result += infile.read()
with open("merged_file.json", "w", encoding='utf-8') as outfile:
outfile.writelines(result)
However, it generate the file with JSON content but all the content is in only one line. How can I append the content as it is in the files.
3
Answers
Maybe this :
You do it by reading and parsing each JSON file, appending the parsed content to a list,
Example below:
hi run it and when done you can edit ALL_DATA._json -> ALL_DATA.json