[Python-Dev] Guarantee ordered dict literals in v3.7? (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Tue Nov 7 01:23:05 EST 2017


On 7 November 2017 at 03:27, Chris Jerdonek <chris.jerdonek at gmail.com> wrote:

On Mon, Nov 6, 2017 at 4:11 AM Nick Coghlan <ncoghlan at gmail.com> wrote:

Getting from the "Works on CPython 3.6+ but is technically non-portable" state to a fully portable correct implementation that ensures a particular key order in the JSON file thus currently requires the following changes: Nick, it seems like this is more complicated than it needs to be. You can just pass sortkeys=True to json.dump() / json.dumps(). I use it for tests and human-readability all the time.

sort_keys is only equivalent to order preservation if the key order you want is alphabetical order. While that's typically a good enough assumption for JSON, it's not the case for things like CSV column order, TOML or ini-file setting order, etc.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list