diff --git a/chalice/app.py b/chalice/app.py index 48b257713..bdb36c895 100644 --- a/chalice/app.py +++ b/chalice/app.py @@ -345,7 +345,8 @@ def __init__(self, body, headers=None, status_code=200): def to_dict(self, binary_types=None): body = self.body if not isinstance(body, _ANY_STRING): - body = json.dumps(body, default=handle_decimals) + body = json.dumps(body, separators=(',', ':'), + default=handle_decimals) response = { 'headers': self.headers, 'statusCode': self.status_code, diff --git a/tests/functional/test_local.py b/tests/functional/test_local.py index 78cb70f7e..f2a5ade0b 100644 --- a/tests/functional/test_local.py +++ b/tests/functional/test_local.py @@ -156,7 +156,7 @@ def test_can_accept_get_request(config, sample_app, local_server_factory): local_server, port = local_server_factory(sample_app, config) response = local_server.make_call(requests.get, '/', port) assert response.status_code == 200 - assert response.text == '{"hello": "world"}' + assert response.text == '{"hello":"world"}' def test_can_get_unicode_string_content_length( @@ -222,7 +222,7 @@ def test_can_accept_multiple_connections(config, sample_app, 'from going though.' ) assert response.status_code == 200 - assert response.text == '{"hello": "world"}' + assert response.text == '{"hello":"world"}' def test_can_import_env_vars(unused_tcp_port, http_session): diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py index afec1ed13..01500006b 100644 --- a/tests/unit/test_app.py +++ b/tests/unit/test_app.py @@ -171,7 +171,7 @@ def test_can_encode_binary_json(sample_app): headers={'Content-Type': 'application/json'} ) encoded_response = response.to_dict(sample_app.api.binary_types) - assert encoded_response['body'] == 'eyJmb28iOiAiYmFyIn0=' + assert encoded_response['body'] == 'eyJmb28iOiJiYXIifQ==' def test_can_parse_route_view_args(): @@ -510,7 +510,7 @@ def index_view(): event = create_event('/index', 'GET', {}) response = demo(event, context=None) - assert response == {'statusCode': 200, 'body': '{"foo": "bar"}', + assert response == {'statusCode': 200, 'body': '{"foo":"bar"}', 'headers': {'Content-Type': 'application/json'}}