import json
import zipfile
import io
zip_stream = io.BytesIO()
new_zip = zipfile.ZipFile(zip_stream, 'w', compression=zipfile.ZIP_DEFLATED)
file_path = './'
zip_file = zipfile.ZipFile(file_path + "zip_001.zip", "w") # "w": write 모드
data = {'aaa': 1629, 'bbb': 1675, 'ccc': 2042}
json_str = json.dumps(data, indent=4) + '\n'
zip_file.writestr(( "aaa" + ".json"), json_str )
data = {'ddd': 1629, 'eee': 1675, 'fff': 2042}
json_str = json.dumps(data, indent=4) + '\n'
zip_file.writestr(( "bbb" + ".json"), json_str )
new_zip.close() |