Skip to content

Instantly share code, notes, and snippets.

@Dascienz
Created September 28, 2021 21:34
Show Gist options
  • Save Dascienz/f44e8b7729960c2c0a293c2a85f56089 to your computer and use it in GitHub Desktop.
Save Dascienz/f44e8b7729960c2c0a293c2a85f56089 to your computer and use it in GitHub Desktop.
Test JSON Size
import json
import os
import sys
import uuid
import datetime
config = {}
size = 1000
for i in range(size):
config[i] = {"key": "value}
output = json.dumps(config)
print("Estimated size: " + str(sys.getsizeof(output) / 1024) + "KB")
with open("test.json", 'wb') as outfile:
outfile.write(output.encode())
print("Actual size: " + str(os.path.getsize('test.json') / 1024) + "KB")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment