Skip to content

Instantly share code, notes, and snippets.

@marcelotournier
Created April 8, 2022 15:52
Show Gist options
  • Save marcelotournier/f5519f5bc0609c9fe1b9a77d0e8d2775 to your computer and use it in GitHub Desktop.
Save marcelotournier/f5519f5bc0609c9fe1b9a77d0e8d2775 to your computer and use it in GitHub Desktop.
How to read json zip files
import zipfile
def read_json_zip(path):
"""
Reads all json files inside of a zip file
and appends the result in a list of dictionaries.
"""
json_list = []
zfile = zipfile.ZipFile(path)
# Clean paths if the zip file was generated by mac os...
zpaths = [name for name in zfile.namelist() if '__MACOSX' not in name]
for filename in zpaths:
file = zfile.open(filename)
json_list.append(json.loads(file.read().decode("utf-8")))
file.close()
zfile.close()
return json_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment