Bottle and Json
Simply return a dict. Bottle handles the conversion to JSON for you.
Even dictionaries are allowed. They are converted to json and returned with Content-Type header set to application/json. To disable this feature (and pass dicts to your middleware) you can set bottle.default_app().autojson to False.
@route('/api/status')def api_status(): return {'status':'online', 'servertime':time.time()}
Taken from the documentation.
For some reason, bottle's auto-json feature doesn't work for me. If it doesn't work for you either, you can use this decorator:
def json_result(f): def g(*a, **k): return json.dumps(f(*a, **k)) return g
Also handy:
def mime(mime_type): def decorator(f): def g(*a, **k): response.content_type = mime_type return f(*a, **k) return g return decorator