1

I am trying to write a Python one-liner using xmltodict to convert an XML file to JSON. It seems like there's an issue reading from sys.stdin directly or as sys.stdin.buffer.read():

python -c 'import xmltodict, sys, json; json.dump(xmltodict.parse(sys.stdin, process_namespaces=True), sys.stdout, indent=4);' < foo.xml > bar.json
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
asterisk
  • 13
  • 3

1 Answers1

1

You need to read() stdin - right now you're just trying to parse the underlying TextIOWrapper:

python -c 'import xmltodict, sys, json; json.dump(xmltodict.parse(sys.stdin.read(), process_namespaces=True), sys.stdout, indent=4);' < foo.xml > bar.json
                                                                            ^-- Here
b_c
  • 1,202
  • 13
  • 24