Created
May 10, 2022 15:44
-
-
Save KaulSe/bd41a80e22bfb44c8d90dbe2ba86a684 to your computer and use it in GitHub Desktop.
Pipe XML to json; cat file.xml | python3 /tmp/xmltojson.py | jq
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 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