Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON to XML in Python

Tags:

python

json

xml

I see a number of questions on SO asking about ways to convert XML to JSON, but I'm interested in going the other way. Is there a python library for converting JSON to XML?


Edit: Nothing came back right away, so I went ahead and wrote a script that solves this problem.

Python already allows you to convert from JSON into a native dict (using json or, in versions < 2.6, simplejson), so I wrote a library that converts native dicts into an XML string.

https://github.com/quandyfactory/dict2xml

It supports int, float, boolean, string (and unicode), array and dict data types and arbitrary nesting (yay recursion).

I'll post this as an answer once 8 hours have passed.

like image 918
Ryan McGreal Avatar asked Jan 24 '12 14:01

Ryan McGreal


1 Answers

Nothing came back right away, so I went ahead and wrote a script that solves this problem.

Python already allows you to convert from JSON into a native dict (using json or, in versions < 2.6, simplejson), so I wrote a library that converts native dicts into an XML string.

https://github.com/quandyfactory/dict2xml

It supports int, float, boolean, string (and unicode), array and dict data types and arbitrary nesting (yay recursion).

like image 53
Ryan McGreal Avatar answered Sep 24 '22 20:09

Ryan McGreal