Skip to content

Loading…

Template filter: tojson and sort_keys #922

Closed
b4stien opened this Issue · 3 comments

3 participants

@b4stien

I spent couple of hours yesterday trying to understand why tojson output had a different order from json.dumps order.

The thing is that Flask sets sort_keys to True by default (see https://github.com/mitsuhiko/flask/blob/master/flask/json.py#L102). Is it possible to add something regarding this, and the JSON_SORT_KEYS in the doc ?

@nZac

http://flask.pocoo.org/docs/api/#flask.Flask.default_config does mention how JSON_SORT_KEYS is set to a default of True.

Would it be helpful to add something in the API documentation here: http://flask.pocoo.org/docs/api/#module-flask.json?

@b4stien

Ok, it's written in the default's config dict, but there is no explanation, nowhere, of this behaviour or this setting.

It's not that straightforward for a template filter to re-order outputs by default, well, at least it wasn't for me :)

@mitsuhiko mitsuhiko closed this in ea656a8
@mitsuhiko
Owner

The docs mention that now. Keep in mind though that "flask.json" has the same behavior and you should be using this module instead of the stdlib one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.