Essentially, I have a list of JSON files that I need information extracted from which is saved in a variable called json_files.
The information from these files needs to then be aggregated and transferred into a new file called summary.json.
Currently, I am able to do this with the following lines of code but only for one file at a time by specifying an index:
with open(json_files[1]) as f:
data = json.load(f)
with open('summary.json', 'w') as f:
json.dump(data, f, indent=2)
However, if I try using a for loop like as follows, I get a TypeError: list indices must be integers or slicers, not str
for i in json_files:
with open(json_files[i]) as f:
data = json.load(f)
with open('summary.json', 'w') as f:
json.dump(data, f, indent=2)
Thus, I was wondering what would be the best way to load information from multiple json files and then combine that into 1 new large json file?
Thanks in advance
ihere isn't an index, it's the actual value.