Template filter: tojson and sort_keys #922

Closed
b4stien opened this Issue Dec 5, 2013 · 3 comments

Comments

3 participants
@b4stien

b4stien commented Dec 5, 2013

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

This comment has been minimized.

Show comment
Hide comment
@nZac

nZac Jan 23, 2014

Contributor

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?

Contributor

nZac commented Jan 23, 2014

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

This comment has been minimized.

Show comment
Hide comment
@b4stien

b4stien Jan 23, 2014

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 :)

b4stien commented Jan 23, 2014

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 Feb 8, 2014

mitsuhiko added a commit that referenced this issue Feb 8, 2014

Merge pull request #962 from nZac/JSON-Support-doc-update
added a note to the api documentation about JSON_SORT_KEYS. Fixes #922
@mitsuhiko

This comment has been minimized.

Show comment
Hide comment
@mitsuhiko

mitsuhiko Feb 8, 2014

Member

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.

Member

mitsuhiko commented Feb 8, 2014

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