0

Simple enough situation; I'm working from within a directory which contains a script, and a subdirectory at the same level which contains many JSON files.

Using ideally Python, I'd like to combine all of the JSON files into one. Depending on your suggestion, this may leave behind redundant headers, but I can pop those off the JSON as I convert that file into a python dictionary object. Not a problem.

The problem is that I have been unable to combine the files into one. I'm practicing on text files for a start, to no avail. I'm using the python "os" module, but no luck. Keenly;

path = "/Users/me/ScriptsAndData/BagOfJSON"
...

for filename in os.listdir(path):
    with open(filename, 'rb') as read file:
    ....

Results in the error;

   with open(filename, 'rb') as readfile:
FileNotFoundError: [Errno 2] No such file or directory: 'firstFile.JSON'

And this finds and names the first file from within the directory, but doesn't operate on it like a file.

tldr;

I'm trying to merge multiple JSON files, all located within a single directory, into a single JSON file. If you know how to do this for any filetype, I'd be happy to know how you do it, then build from there.

Cheers!

0 Answers0