Created
January 22, 2018 08:59
-
-
Save mindey/56dce86203b0e5eeb6431c555a079e77 to your computer and use it in GitHub Desktop.
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
### 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