Subject: bug#24252: 25.1; json.el doesn't distinguish null and empty object

From: Dmitry Gutov <[email-masked]>
Date: Sat, 27 Aug 2016 03:05:41 +0300

Hi Yoichi,

Thanks, but the changes to tests like below seem to indicate that the 
code breaks backward compatibility in certain respect. I'm not sure 
we'll want to merge it for that reason.

I'd like to know what other developers think.

On 08/21/2016 06:06 PM, Yoichi Nakayama wrote:

>  (ert-deftest test-json-plist-to-alist ()
>    (should (equal (json--plist-to-alist '()) '()))
> -  (should (equal (json--plist-to-alist '(:a 1)) '((:a . 1))))
> +  (should (equal (json--plist-to-alist '(:a 1)) '((a . 1))))
> +  (let ((json-key-type 'keyword))
> +    (should (equal (json--plist-to-alist '(:a 1)) '((:a . 1)))))
>    (should (equal (json--plist-to-alist '(:a 1 :b 2 :c 3))
> -                 '((:a . 1) (:b . 2) (:c . 3)))))
> +                 '((a . 1) (b . 2) (c . 3)))))
>
>  (ert-deftest test-json-advance ()
>    (json-tests--with-temp-buffer "{ \"a\": 1 }"
> @@ -177,9 +179,16 @@ Point is moved to beginning of the buffer."
>                   "\"\\nasdфыв\\u001f\u007ffgh\\t\"")))
>
>  (ert-deftest test-json-encode-key ()
> -  (should (equal (json-encode-key "foo") "\"foo\""))
> -  (should (equal (json-encode-key 'foo) "\"foo\""))
> -  (should (equal (json-encode-key :foo) "\"foo\""))
> +  (let ((json-key-type 'string))
> +    (should (equal (json-encode-key "foo") "\"foo\""))
> +    (should-error (json-encode-key t) :type 'json-key-format))
> +  (let ((json-key-type 'symbol))
> +    (should (equal (json-encode-key 'foo) "\"foo\""))
> +    (should (equal (json-encode-key t) "\"t\""))
> +    (should (equal (json-encode-key :t) "\":t\"")))
> +  (let ((json-key-type 'keyword))
> +    (should (equal (json-encode-key :foo) "\"foo\""))
> +    (should-error (json-encode-key t) :type 'json-key-format))
>    (should-error (json-encode-key 5) :type 'json-key-format)
>    (should-error (json-encode-key ["foo"]) :type 'json-key-format)
>    (should-error (json-encode-key '("foo")) :type 'json-key-format))
> @@ -238,9 +247,9 @@ Point is moved to beginning of the buffer."
>    (let ((hash-table (make-hash-table))
>          (json-encoding-object-sort-predicate 'string<)
>          (json-encoding-pretty-print nil))
> -    (puthash :a 1 hash-table)
> -    (puthash :b 2 hash-table)
> -    (puthash :c 3 hash-table)
> +    (puthash "a" 1 hash-table)
> +    (puthash "b" 2 hash-table)
> +    (puthash "c" 3 hash-table)
>      (should (equal (json-encode hash-table)
>                     "{\"a\":1,\"b\":2,\"c\":3}"))))
>
> @@ -261,7 +270,7 @@ Point is moved to beginning of the buffer."
>      (should (equal (json-encode plist) "{\"a\":1,\"b\":2,\"c\":3}"))))
>
>  (ert-deftest test-json-encode-alist-with-sort-predicate ()
> -  (let ((alist '((:c . 3) (:a . 1) (:b . 2)))
> +  (let ((alist '((c . 3) (a . 1) (b . 2)))
>          (json-encoding-object-sort-predicate 'string<)
>          (json-encoding-pretty-print nil))
>      (should (equal (json-encode alist) "{\"a\":1,\"b\":2,\"c\":3}"))))
> @@ -270,7 +279,7 @@ Point is moved to beginning of the buffer."
>    (let ((json-encoding-pretty-print nil))
>      (should (equal (json-encode-list '(:a 1 :b 2))
>                     "{\"a\":1,\"b\":2}"))
> -    (should (equal (json-encode-list '((:a . 1) (:b . 2)))
> +    (should (equal (json-encode-list '((a . 1) (b . 2)))
>                     "{\"a\":1,\"b\":2}"))
>      (should (equal (json-encode-list '(1 2 3 4)) "[1,2,3,4]"))))