Created
July 26, 2018 12:49
-
-
Save LouisAmon/4bd79b8ab80d3851601f3f9016300ac4 to your computer and use it in GitHub Desktop.
How to compress JSON-able data using gzip (Python 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import gzip | |
def compress_data(data): | |
# Convert to JSON | |
json_data = json.dumps(data, indent=2) | |
# Convert to bytes | |
encoded = json_data.encode('utf-8') | |
# Compress | |
compressed = gzip.compress(encoded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful. Thanks!