From 973d5d457bdf70913b1fd4404d1134d4f7a3dd0e Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 14 Feb 2026 18:56:44 +0100 Subject: [PATCH] Prefer value< with new 'sort' in json.el MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that json.el uses the new sort calling convention, there's no need to prefer string< over value<, which may even run faster. Suggested by Mattias EngdegÄrd . * lisp/json.el (json-encoding-object-sort-predicate): Mention value< in docstring. (json-pretty-print-buffer-ordered, json-pretty-print-ordered): Use value< in place of string<. * test/lisp/json-tests.el (test-json-encode-hash-table-sort): Use value< as json-encoding-object-sort-predicate in at least one test. --- lisp/json.el | 6 +++--- test/lisp/json-tests.el | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/json.el b/lisp/json.el index 82cc9c71bf5..7e4c1b05518 100644 --- a/lisp/json.el +++ b/lisp/json.el @@ -142,7 +142,7 @@ Used only when `json-encoding-pretty-print' is non-nil.") "Sorting predicate for JSON object keys during encoding. If nil, no sorting is performed. Else, JSON object keys are ordered by the specified sort predicate during encoding. For -instance, setting this to `string<' will have JSON object keys +instance, setting this to `value<' will have JSON object keys ordered alphabetically.") (defvar json-pre-element-read-function nil @@ -840,14 +840,14 @@ With prefix argument MINIMIZE, minimize it instead." "Pretty-print current buffer with object keys ordered. With prefix argument MINIMIZE, minimize it instead." (interactive "P") - (let ((json-encoding-object-sort-predicate #'string<)) + (let ((json-encoding-object-sort-predicate #'value<)) (json-pretty-print-buffer minimize))) (defun json-pretty-print-ordered (begin end &optional minimize) "Pretty-print the region with object keys ordered. With prefix argument MINIMIZE, minimize it instead." (interactive "r\nP") - (let ((json-encoding-object-sort-predicate #'string<)) + (let ((json-encoding-object-sort-predicate #'value<)) (json-pretty-print begin end minimize))) (provide 'json) diff --git a/test/lisp/json-tests.el b/test/lisp/json-tests.el index 4fb6a9195ce..9d9df61ee70 100644 --- a/test/lisp/json-tests.el +++ b/test/lisp/json-tests.el @@ -657,7 +657,7 @@ Point is moved to beginning of the buffer." "{\n \"c\": 3,\n \"b\": 2,\n \"a\": 1}"))))) (ert-deftest test-json-encode-hash-table-sort () - (let ((json-encoding-object-sort-predicate #'string<) + (let ((json-encoding-object-sort-predicate #'value<) (json-encoding-pretty-print nil)) (pcase-dolist (`(,in . ,out) '((#s(hash-table) . "{}")