Skip to content
Advertisement

How to combine a string of multiple json gz files in a list into one json gz file then open the file?

I have a list of json gz https files

FYI: these files are not real files due to privacy laws but mimic the exact structure.

JavaScript

My goal is to combine all these json gz files into one large json gz file.

I’ve tried numerous ways to do this by referencing other Stack Overflow questions; however, I am unable to find exactly what I am looking for.

This comment helped me somewhat, but in my situation, I believe that I need to add requests to get the file since it is an http.

Python 3, read/write compressed json objects from/to gzip file

JavaScript

Error:

JavaScript

Got this error on the correct https since this is changed for privacy.

Advertisement

Answer

This comment helped me somewhat, but in my situation, I believe that I need to add requests to get the file since it is an http.

Indeed built-in open function does not support HTTP access, however in this case I would use urllib.request.urlopen, consider following example using example file provided by Mozilla

JavaScript

gives output

JavaScript

Explanation: first with does open file under specified URL then gzip.open is used to decompress is, so json.load can be used to parse JSON and get data (data is dict). Note that all used imports pertain to standard library, so you do not need to install any external package.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement