From 8f589454a29dd4cb2a69a1fe50274279eaad510c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Mon, 1 Apr 2024 16:58:03 +0200 Subject: [PATCH] Update JSON parser test and docs * test/src/json-tests.el (json-parse-string/object): Duplicated object keys are now retained in alist and plist output. * etc/NEWS: Mention it. (cherry picked from commit dbfe3cae2d9497fb14c83f26425f9421d1ef57cb) --- etc/NEWS | 10 +++++++++- test/src/json-tests.el | 7 ++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 45c6f6dccdd..380e257dc1f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1838,8 +1838,16 @@ non-interactively. This special behavior is removed in this version of Emacs, for consistency with the common Emacs behavior where minibuffer history is reserved for past minibuffer inputs. +** JSON + +--- +*** The parser keeps duplicated object keys in alist and plist output. +A JSON object such as '{"a":1,"a":2}' will now be translated into the +Lisp values '((a . 1) (a . 2))' or '(:a 1 :a 2)' if alist or plist +object types are requested. + --- -** The JSON parser sometimes signals different types of errors. +*** The parser sometimes signals different types of errors. It will now signal 'json-utf8-decode-error' for inputs that are not correctly UTF-8 encoded. diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 628a5a3de57..8b730ef8c90 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el @@ -156,9 +156,6 @@ ) (ert-deftest json-parse-string/object () - :expected-result :failed - ;; FIXME: This currently fails. Should the parser deduplicate keys? - ;; Never, always, or for alist and plist only? (let ((input "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n")) (let ((actual (json-parse-string input))) @@ -167,9 +164,9 @@ (should (equal (cl-sort (map-pairs actual) #'string< :key #'car) '(("abc" . [9 :false]) ("def" . :null))))) (should (equal (json-parse-string input :object-type 'alist) - '((abc . [9 :false]) (def . :null)))) + '((abc . [1 2 t]) (def . :null) (abc . [9 :false])))) (should (equal (json-parse-string input :object-type 'plist) - '(:abc [9 :false] :def :null))))) + '(:abc [1 2 t] :def :null :abc [9 :false]))))) (ert-deftest json-parse-string/object-unicode-keys () (let ((input "{\"é\":1,\"☃\":2,\"𐌐\":3}")) -- 2.39.5