I have 3 json files as below:
test1.json:
{"item":"book1","price":"10.00","location":"library"}
test2.json:
{"item":"book2","price":"15.00","location":"store"}
test3.json:
{"item":"book3","price":"9.50","location":"store"}
I have this code:
import json
import glob
result = ''
for f in glob.glob("*.json"):
with open (f, "r") as infile:
result += infile.read()
with open("m1.json", "w") as outfile:
outfile.writelines(result)
I get the following output:
{"item":"book1","price":"10.00","location":"library"}
{"item":"book2","price":"15.00","location":"store"}
{"item":"book3","price":"9.50","location":"store"}
Is it possible to get each file as a new line separated by a comma like below?
{"item":"book1","price":"10.00","location":"library"}, <-- line 1
{"item":"book2","price":"15.00","location":"store"}, <-- line 2
{"item":"book3","price":"9.50","location":"store"} <-- line 3