-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
29 lines (27 loc) · 755 Bytes
/
example.py
File metadata and controls
29 lines (27 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
from converter import json_to_xml, xml_to_json
if __name__ == "__main__":
json_data = {
"person": {
"name": "John Doe",
"age": 30,
"hobbies": ["reading", "cycling", "hiking"]
}
}
xml_output = json_to_xml(json_data, root_name="data")
print("XML Output:\n", xml_output)
xml_data = """
<data>
<person>
<name>John Doe</name>
<age>30</age>
<hobbies>
<item>reading</item>
<item>cycling</item>
<item>hiking</item>
</hobbies>
</person>
</data>
"""
json_output = xml_to_json(xml_data)
print("\nJSON Output:\n", json.dumps(json_output, indent=4))