Possible Duplicate:
Converting XML to JSON using Python?
I am importing an XML feed and trying to convert it to JSON for output. I’m getting this error:
TypeError: <xml.dom.minidom.Document instance at 0x72787d8> is not JSON serializable
Unfortunately I know next to nothing about Python. I’m developing this on the Google App Engine. I could use some help, because my little 2 hour hack that was going so well is now on its 3rd day.
XML data:
<?xml version='1.0' ?><eveapi version='2'> <currentTime>2009-01-25 15:03:27</currentTime> <result> <rowset columns='name,characterID,corporationName,corporationID' key='characterID' name='characters'> <row characterID='999999' corporationID='999999' corporationName='filler data' name='someName'/> </rowset> </result> <cachedUntil>2009-01-25 15:04:55</cachedUntil> </eveapi>
My code:
class doproxy(webapp.RequestHandler): def get(self): apiurl = 'http://api.eve-online.com' path = self.request.get('path'); type = self.request.get('type'); args = '&'+self.request.get('args'); #assemble api url url = apiurl+path #do GET request if type == 'get': result = urlfetch.fetch(url,'','get'); #do POST request if type == 'post': result = urlfetch.fetch(url,args,'post'); if result.status_code == 200: dom = minidom.parseString( result.content ) #.encode( 'utf-8' ) ) dom2json = simplejson.dump(dom,'utf-8')
The attitude of the question isn’t going to help with getting answers from these same Python users.
As is mentioned in the answers to this related question, there is no 1-to-1 correspondence between XML and JSON so the conversion can’t be done automatically.
In the documentation for
simplejsonyou can find the list of types that it’s able to serialize, which are basically the native Python types (dict, list, unicode, int, float, True/False, None).So, you have to create a Python data structure containing only these types, which you will then give to
simplejson.dump().