Tauseef Hussain
Tauseef Hussain

Reputation: 1079

Return Json Array with bottle

I am trying to return a Json array with Bottle. The code is:

@app.get('/getmyname')
def getmyname():
    ret = """{
            "chart": {
            "type": "column",
            }}""" 
    return json.dumps(ret)

However i get some unwanted characters in the resul which looks like this:

"{\n\t\t\t\t\"chart\": {\n\t\t\t\t\t\"type\": \"column\",\n\t\t\t\t}}"

How could i fix this?

Upvotes: 0

Views: 719

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599590

ret is already a JSON string. There is no need to call json.dumps on it.

Either return ret directly, or create it as a Python dict and then dump it to JSON:

ret = {
        "chart": {
            "type": "column",
         }
      }
return json.dumps(ret)

Upvotes: 5

Related Questions