Message 82864 - Python tracker (original) (raw)

Same reason as for config files and yaml files. Sometimes those files represent human edited input and if a machine re-edits, filters, or copies, it is nice to keep the original order (though it may make no semantic difference to the computer).

For example, jsonrpc method invocations are done with objects having three properties (method, params, id). The machine doesn't care about the order of the properties but a human reader prefers the order listed:

--> {"method": "postMessage", "params": ["Hello all!"], "id": 99} <-- {"result": 1, "error": null, "id": 99}

If you're testing a program that filters json data (like a typical xml task), it is nice to write-out data in the same order received (failing to do that is a common complaint about misdesigned xml filters):

--> {{"title": "awk", "author":"aho", "isbn":"123456789X"}, {"title": "taocp", "author":"knuth", "isbn":"987654321X"}" <-- {{"title": "awk", "author":"aho"}, {"title": "taocp", "author":"knuth"}}

Semantically, those entries can be scrambled; however, someone reading the filtered result desires that the input and output visually correspond as much as possible. An object_pairs_hook makes this possible.