Skip to content

Instantly share code, notes, and snippets.

@mindey
Created January 22, 2018 08:59
Show Gist options
  • Save mindey/56dce86203b0e5eeb6431c555a079e77 to your computer and use it in GitHub Desktop.
Save mindey/56dce86203b0e5eeb6431c555a079e77 to your computer and use it in GitHub Desktop.
### For finding schema
def schematize(obj):
'''
Get schema of nested JSON, assuming first item in lists.
'''
if isinstance(obj, dict):
return {k: schematize(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [schematize(elem) for elem in obj][:1]
else:
return type(obj) # no container, just values (str, int, float)
### //
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment