Skip to content

Instantly share code, notes, and snippets.

@akshaykarnawat
Created February 6, 2018 03:42
Show Gist options
  • Save akshaykarnawat/2fa69ae7f97ab9cdc2c6eb680ccbe682 to your computer and use it in GitHub Desktop.
Save akshaykarnawat/2fa69ae7f97ab9cdc2c6eb680ccbe682 to your computer and use it in GitHub Desktop.
Recursive Object Dictionary in Python
import uuid
import json
max_count = 200 #982 # use sys.setrecursionlimit(1000) for higher limits
count = 0
dd = { 'id': str(uuid.uuid4()), 'obj': None }
def objectOfObject(obj, count, max_count):
# print(obj)
obj['obj'] = { 'id': str(uuid.uuid4()) }
count += 1
if count != max_count:
objectOfObject(obj['obj'], count, max_count)
objectOfObject(dd, count, max_count)
# print(json.dumps(dd))
with open('recursive_object.json', 'w') as file:
json.dump(dd, file, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment