'Name object/lists when combining json files in Python

I have a series of python scripts doing Oracle SQL database checks and outputting the results into individual json files per output. That's all working fine, albeit there is probably better ways to do it.

Then using the following which I found on here in merging the json files into a single json:

import json
import glob

result = []
for f in glob.glob("*.json"):
    with open(f, "rb") as infile:
        result.append(json.load(infile))

with open("merged_file.json", "w") as outfile:
     json.dump(result, outfile)

This works roughly how I wanted the output to be, the only issue I'm facing is the "names" of the result sets (I'm sure my lack of terminology knowledge is what's made this hard).

To visualize what I mean, this is the output result without the data (I realise this isn't the correct output format, this is from a gui viewer of the file to better see formatting):

[]JSON
 {}0
   {}RMTID
   {}FLIGHTS
   {}HOURLY
   {}WEATHER
   {}CALIBRATION
   {}GAPS
 {}1
   {}RMTID
   {}FLIGHTS
   {}HOURLY
   {}WEATHER
   {}CALIBRATION
   {}GAPS

I'm looking to have the 0 and 1 be the labels of the result set, so that the output would look like:

[]JSON
 {}LAX
   {}RMTID
   {}FLIGHTS
   {}HOURLY
   {}WEATHER
   {}CALIBRATION
   {}GAPS
 {}LGW
   {}RMTID
   {}FLIGHTS
   {}HOURLY
   {}WEATHER
   {}CALIBRATION
   {}GAPS

Is that possible with Python? Or should I be looking at alternative solutions?

I've seen other suggestions for similar questions that suggest just taking the outputs directly into one file rather then merging multiple files, however the results are from different database connections and finding a solution for "queuing" database connections and storing outputs has been above my skill level.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source