Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generator of the example JSON file to illustrate article about ijson module on https://polydev.pl
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
You can’t perform that action at this time.