Skip to content

Instantly share code, notes, and snippets.

@Zulko
Created June 7, 2018 13:25
Show Gist options
  • Save Zulko/4e75554595674f66cfd1fa3d58b8968b to your computer and use it in GitHub Desktop.
Save Zulko/4e75554595674f66cfd1fa3d58b8968b to your computer and use it in GitHub Desktop.
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