[Flask] JSON is always pretty
Skip Montanaro
skip.montanaro at gmail.com
Tue Feb 28 14:07:33 EST 2017
I just started using Flask (v 0.12 in a Conda Python 2.7 environment)
as a tool to implement a RESTful server. So far, it looks great. I'm
just debugging things and working with small output, so it's not a
huge deal just now, but no matter what I do, flask.jsonify() seems to
always pretty print the returned JSON. I've been running my
application like this:
FLASK_DEBUG=1 FLASK_APP=map.py flask run
then in map.py, I tweak the config parameters like so:
app = Flask(__name__)
DEBUG = os.environ.get("FLASK_DEBUG") == "1"
app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=DEBUG)
Even if I leave FLASK_DEBUG off the command line or explicitly set it
to "0", the JSON comes out formatted. Thinking I might have misread
the documentation of JSON_PRETTYPRINT_REGULAR, I changed the update
call to
app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=not DEBUG)
but that had no effect. The output is still pretty.
Am I supposed to be unable to explicitly override JSON pretty printing
at the level of flask.jsonify()? Do I need to drop down a level to
flask.json.dumps() (where it also seems to be uncontrollable, but
always condensed)?
Thanks,
Skip Montanaro
More information about the Flask
mailing list