HI,
I am new to python and learning , need help converting json file to xml . I have below code ( found on web ) modified a bit but is not parsing the whole file only few lines:
appreciate any help!
Thanks!
Output:
I am new to python and learning , need help converting json file to xml . I have below code ( found on web ) modified a bit but is not parsing the whole file only few lines:
appreciate any help!
Thanks!
Output:
Output:<Core>
<case_id>
CASE_17BC95
</case_id>
<case_id>
CASE_17D59E
</case_id>
</Core>t]
Process finished with exit code 0
here is the code:import json def json2xml(json_obj, Line_spacing=""): result_list = list() json_obj_type = type(json_obj) if json_obj_type is list: for sub_elem in json_obj: result_list.append(json2xml(sub_elem, Line_spacing)) return "\n".join(result_list) if json_obj_type is dict: for tag_name in json_obj: sub_obj = json_obj[tag_name] result_list.append("%s<%s>" % (Line_spacing, tag_name)) result_list.append(json2xml(sub_obj, "\t" + Line_spacing)) result_list.append("%s</%s>" % (Line_spacing, tag_name)) # print(result_list) return "\n".join(result_list) return "%s%s" % (Line_spacing, json_obj) with open ("C://Users//test//Documents//json2.txt") as s: data = json.load(s) print(json2xml(data))