Xml-To-Json
Sat 17 May 2025
title: "XML to JSON" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false
import xmltodict
import pprint
import json
xml_content = """
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
"""
xml_content
"\n <note>\n <to>Tove</to>\n <from>Jani</from>\n <heading>Reminder</heading>\n <body>Don't forget me this weekend!</body>\n </note>\n"
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(json.dumps(xml_content))
('"\\n <note>\\n <to>Tove</to>\\n <from>Jani</from>\\n '
"<heading>Reminder</heading>\\n <body>Don't forget me this "
'weekend!</body>\\n </note>\\n"')
Score: 5
Category: basics