Skip to content

Instantly share code, notes, and snippets.

@trivelt
Created July 20, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trivelt/ae7b06508d216c670a3cdcccfab2c374 to your computer and use it in GitHub Desktop.
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
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