We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 607cbf2 commit dce1d7aCopy full SHA for dce1d7a
json_to_xml/json_to_xml.py
@@ -1,5 +1,5 @@
1
import json
2
-import xml.etree.ElementTree as ET
+
3
4
def json_to_xml(json_obj, line_padding=""):
5
"""
@@ -30,6 +30,9 @@ def save_xml_file(xml_str, output_file):
30
31
32
def main():
33
+ """
34
+ Main function to convert a JSON file to an XML file.
35
36
# Input JSON file
37
input_json_file = "test-input.json"
38
# Output XML file
@@ -44,7 +47,9 @@ def main():
44
47
xml_data = json_to_xml(json_data)
45
48
46
49
# Add XML header
- xml_data_with_header = f"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n{xml_data}"
50
+ xml_data_with_header = (
51
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xml_data
52
+ )
53
54
# Save to XML file
55
save_xml_file(xml_data_with_header, output_xml_file)
0 commit comments