repl.it
@functorflow/

xml-json

Python

Convert XML text to JSON (and vice versa).

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from functorflow import ff

# 📦 Convert XML text to JSON (and vice versa).

xml = '<?xml version="1.0" encoding="utf-8"?><note importance="high" logged="true"><title>Happy</title><todo>Work</todo><todo>Play</todo></note>'


json = ff('xml-json').json(xml, options={'compact': True, 'spaces': 4})

print(json)

# 📦 JSON -> XML
opt = {'compact': True, 'ignoreComment': True, 'spaces': 4}
xml = ff('xml-json').xml(json, options=opt)

print(xml)