Skip to content


Template filter: tojson and sort_keys #922

b4stien opened this Issue · 3 comments

3 participants


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 Is it possible to add something regarding this, and the JSON_SORT_KEYS in the doc ?

@nZac 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:


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

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.