Created
July 20, 2020 15:57
-
-
Save trivelt/ae7b06508d216c670a3cdcccfab2c374 to your computer and use it in GitHub Desktop.
Generator of the example JSON file to illustrate article about ijson module on https://polydev.pl
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 random | |
from uuid import uuid4 | |
AVAILABLE_SERVICES = ["FooService", "BarService", "FooBarService", "Unknown", "Secret"] | |
data = {"data": []} | |
NUMBER_OF_ACCOUNTS = 100000 | |
for i in range(NUMBER_OF_ACCOUNTS): | |
configs = [] | |
number_of_configs = random.randint(1,5) | |
for _ in range(number_of_configs): | |
config = { | |
"uuid": str(uuid4()), | |
"port": random.randint(3000, 9999), | |
"service": random.choice(AVAILABLE_SERVICES) | |
} | |
configs.append(config) | |
account = { | |
"account_name": "ACCOUNT-{}".format(i), | |
"uuid": str(uuid4()), | |
"configs": configs | |
} | |
data["data"].append(account) | |
with open("account_data.json", "w") as f: | |
json.dump(data, f, indent=4, separators=(',', ': ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment