-1

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")
6
  • Why was this down voted? Yeah the OP is definitely new to Python and coding but the fastest way to learn is to ask questions like this. Commented Jan 25, 2009 at 15:57
  • I believe the way the question is written caused the downvoting. Commented Jan 25, 2009 at 16:50
  • probably down voted because he said python is not documented... Commented Jan 25, 2009 at 17:08
  • Question isn't well written but it's a decent one. I've edited. Let's remove some downvotes -this is probably useful to other people. Commented Jan 25, 2009 at 17:59
  • Why do you ask about the same (identical title) thing you asked 2 days ago at stackoverflow.com/questions/471946 ? Commented Oct 15, 2012 at 17:15

1 Answer 1

9

I'm quickly coming to the opinion that Python is potentially a great language, but that none of its users know how to actually document anything in a clear and concise way.

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 simplejson you 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().

Sign up to request clarification or add additional context in comments.

1 Comment

@Geuis I recommend you pick up an introduction to Computer science book, your going to be banging your head against a wall until you start getting the big picture of data structures and software design.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.