From c629f69e698fd815969e91e5c8c59323c61a256c Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 2 Jun 2013 11:54:22 +0100 Subject: [PATCH] Make the JSON module work better in the absence of an application context --- flask/json.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flask/json.py b/flask/json.py index 875af67e..2437a20c 100644 --- a/flask/json.py +++ b/flask/json.py @@ -92,18 +92,22 @@ class JSONDecoder(_json.JSONDecoder): def _dump_arg_defaults(kwargs): """Inject default arguments for dump functions.""" - kwargs.setdefault('sort_keys', True) if current_app: kwargs.setdefault('cls', current_app.json_encoder) if not current_app.config['JSON_AS_ASCII']: kwargs.setdefault('ensure_ascii', False) kwargs.setdefault('sort_keys', current_app.config['JSON_SORT_KEYS']) + else: + kwargs.setdefault('sort_keys', True) + kwargs.setdefault('cls', JSONEncoder) def _load_arg_defaults(kwargs): """Inject default arguments for load functions.""" if current_app: kwargs.setdefault('cls', current_app.json_decoder) + else: + kwargs.setdefault('cls', JSONDecoder) def dumps(obj, **kwargs):