Subject: bug#21616: [PATCH] Enable sorting of JSON object keys when encoding

From: Dmitry Gutov <[email-masked]>
Date: Mon, 9 Nov 2015 02:01:25 +0200

Hi Simen,

On 10/04/2015 10:15 PM, Simen Heggestøyl wrote:
> When working with JSON data, it is often convenient to be able to
> prettify the data, and having object keys sorted in a fixed order.
> This patch adds the variable `json-encoding-object-sort-key' which

I think it's a "predicate", not a "key". See the argument names in 
`sort' and `cl-sort': the latter has a :key keyword argument, but it has 
different purpose.

Call it json-[encode-]key-sort-predicate, maybe?

> This gets rid of a lot of redundant code from `json-encode-hash-table'
> and `json-encode-plist' by going via alists, and using the logic of
> `json-encode-alist' commonly for all the structures.

The unification part makes me concerned, again, from the performance 
standpoint. Did you do any measuring here?

> I was in doubt whether to make `json-pretty-print-ordered' and
> `json-pretty-print-buffer-ordered' their own commands, or if it would
> be better to provide this functionality by having `json-pretty-print'
> and `json-pretty-print-buffer' accept prefix arguments. I decided on
> the former, because I think it makes the commands easier to discover.

Yes, making them separate seems to be more in line with other Emacs 
commands.