Created
June 7, 2018 13:25
-
-
Save Zulko/4e75554595674f66cfd1fa3d58b8968b 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
import json | |
def schema(json_object): | |
if hasattr(json_object, 'items'): | |
result = {} | |
for k, v in json_object.items(): | |
if hasattr(v, 'items'): | |
result[k] = schema(v) | |
elif isinstance(v, list): | |
result[k] = [schema(v[0]), '...'] | |
else: | |
result[k] = v.__class__.__name__ | |
return result | |
else: | |
return json_object | |
with open(xml_file, 'r') as f: | |
content = f.read() | |
data = xmltodict.parse(content) | |
s = schema(data) | |
print (json.dumps(s, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment