The dictionary seems to be JSON encoded twice, which is equivalent to:
json.dumps(json.dumps({ "color" : "color", "message" : "message" }))
Perhaps your Python system automatically JSON encodes the result? Try instead:
def returnJSON(color, message=None): return { "color" : "color", "message" : "message" }
EDIT:
To use the Pyramid custom renderer that generates JSON the way you want, try this (based on visualization documents and visualization sources ).
At startup:
from pyramid.config import Configurator from pyramid.renderers import JSON config = Configurator() config.add_renderer('json_with_custom_default', JSON(default=json_util.default))
Then you use the renderer 'json_with_custom_default' to use:
@view_config(route_name='CreateNewAccount', request_method='GET', renderer='json_with_custom_default')
EDIT 2
Another option would be to return a Response
object, which it should not modify. For instance.
from pyramid.response import Response def returnJSON(color, message): json_string = json.dumps({"color": color, "message": message}, default=json_util.default) return Response(json_string)
source share