Skip to content

Instantly share code, notes, and snippets.

@KaulSe
Created May 10, 2022 15:44
Show Gist options
  • Select an option

  • Save KaulSe/bd41a80e22bfb44c8d90dbe2ba86a684 to your computer and use it in GitHub Desktop.

Select an option

Save KaulSe/bd41a80e22bfb44c8d90dbe2ba86a684 to your computer and use it in GitHub Desktop.
Pipe XML to json; cat file.xml | python3 /tmp/xmltojson.py | jq
#!/usr/bin/env python3
import json
import sys
import xmltodict
import fileinput
def main():
if len(sys.argv) != 1:
print("Usage: xml-to-json")
for line in fileinput.input():
try:
data = xmltodict.parse(line)
print(json.dumps(data))
except Exception as e:
pass
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment