Skip to content

Instantly share code, notes, and snippets.

@ryanwoodsmall
Last active February 14, 2019 17:06
Show Gist options
  • Save ryanwoodsmall/066fdb7b4152fa4fc1b1a8708cae6cd5 to your computer and use it in GitHub Desktop.
Save ryanwoodsmall/066fdb7b4152fa4fc1b1a8708cae6cd5 to your computer and use it in GitHub Desktop.
simple python xml -> json conversion using xmltodict
#!/usr/bin/env python
import fileinput
import json
from dicttoxml import dicttoxml
jsonin = ""
jsondict = ""
jsonxml = ""
for line in fileinput.input():
jsonin = jsonin + line
jsondict = json.loads(jsonin)
jsonxml = dicttoxml(jsondict)
#print jsonin
#print jsondict
print jsonxml
#!/usr/bin/env python
import fileinput
import json
import yaml
jsonin = ""
jsondict = ""
jsonyaml = ""
for line in fileinput.input():
jsonin = jsonin + line
jsondict = json.loads(jsonin)
jsonyaml = yaml.safe_dump(jsondict, default_flow_style=False)
#print jsonin
#print jsondict
print jsonyaml
#!/usr/bin/env python
import fileinput
import json
import xmltodict
xmlin = ""
xmldict = ""
xmljson = ""
for line in fileinput.input():
xmlin = xmlin + line
xmldict = xmltodict.parse(xmlin)
xmljson = json.dumps(xmldict)
#print xmlin
#print xmldict
print xmljson
#!/usr/bin/env python
import fileinput
import json
import yaml
yamlin = ""
yamldict = ""
yamljson = ""
for line in fileinput.input():
yamlin = yamlin + line
yamldict = yaml.load(yamlin)
yamljson = json.dumps(yamldict)
#print yamlin
#print yamldict
print yamljson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment