Last active
February 14, 2019 17:06
-
-
Save ryanwoodsmall/066fdb7b4152fa4fc1b1a8708cae6cd5 to your computer and use it in GitHub Desktop.
simple python xml -> json conversion using xmltodict
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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