Skip to content

Instantly share code, notes, and snippets.

@bewestphal
bewestphal / Json2XML
Created June 1, 2016 06:17
Python Function to Convert JSON to XML
def json2xml(json_obj, tag_name=None):
result_list = list()
json_obj_type = type(json_obj)
if json_obj_type is list:
for sub_elem in json_obj:
result_list.append("\n<%s>" % (tag_name))
result_list.append(json2xml(sub_elem, tag_name=tag_name))
tag_name = re.sub('\s\w+="\w+"', '', tag_name)