]> git.eshelyaron.com Git - emacs.git/commitdiff
Update JSON parser test and docs
authorMattias Engdegård <mattiase@acm.org>
Mon, 1 Apr 2024 14:58:03 +0000 (16:58 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 2 Apr 2024 13:30:20 +0000 (15:30 +0200)
* 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
test/src/json-tests.el

index 45c6f6dccdd69b3c178b5ce22c4f28235026e464..380e257dc1f0e23399ad12861e514d9b63e69c0b 100644 (file)
--- 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.
 
index 628a5a3de575dbcec40fc5a9415cfeebc001ff5e..8b730ef8c909363acc1d6fe170d17ba9b123edee 100644 (file)
   )
 
 (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)))
       (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}"))