I am trying to merge "n" number of json files but i need to first load json from filepath and then use it. I referred below link but they already have json data available but in my case i want to first load json data in loop and then merge it. I am looking for generic way of doing it.
How do I merge a list of dicts into a single dict?
My code: I want to first load json data for all the files and then merge it. I am trying something like below but it does not work and give error as TypeError: str , bytes or ospath.like object, not Tuple
def merge_JsonFiles(*file):
result = {}
for f in file:
json_data = loadjson(file)
result = {**json_data}
return result
merge_JsonFiles(file1, file2, file3)
def loadjson(file)
with open(file , 'r') as fh:
return json.load(fh)
Merge logic for two files = {**file1, **file2)