aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPhilipp Stephani2017-12-13 22:41:28 +0100
committerPhilipp Stephani2017-12-24 13:59:25 +0100
commitf552a957ada23a7ff182fc1ab94221ced3ed1713 (patch)
tree359c39cfc24e3c166984717f73884f6c221d1378 /test/src
parent3455192777459a08a38b0adb311a76202e29f48d (diff)
downloademacs-f552a957ada23a7ff182fc1ab94221ced3ed1713.tar.gz
emacs-f552a957ada23a7ff182fc1ab94221ced3ed1713.zip
Accept alists when serializing JSON
* src/json.c (lisp_to_json_toplevel_1): Also accept alists representing objects. * src/json.c (Fjson_serialize): Update docstring. * test/src/json-tests.el (json-serialize/object): Add unit tests for serializing alists. * doc/lispref/text.texi (Parsing JSON): Document that serialization functions accept alists.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/json-tests.el14
1 files changed, 13 insertions, 1 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 5d9f6b3840c..b23439a59fd 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -50,7 +50,19 @@
50 (puthash "abc" [1 2 t] table) 50 (puthash "abc" [1 2 t] table)
51 (puthash "def" :null table) 51 (puthash "def" :null table)
52 (should (equal (json-serialize table) 52 (should (equal (json-serialize table)
53 "{\"abc\":[1,2,true],\"def\":null}")))) 53 "{\"abc\":[1,2,true],\"def\":null}")))
54 (should (equal (json-serialize '((abc . [1 2 t]) (def . :null)))
55 "{\"abc\":[1,2,true],\"def\":null}"))
56 (should (equal (json-serialize nil) "{}"))
57 (should (equal (json-serialize '((abc))) "{\"abc\":{}}"))
58 (should (equal (json-serialize '((a . 1) (b . 2) (a . 3)))
59 "{\"a\":1,\"b\":2}"))
60 (should-error (json-serialize '(abc)) :type 'wrong-type-argument)
61 (should-error (json-serialize '((a 1))) :type 'wrong-type-argument)
62 (should-error (json-serialize '((1 . 2))) :type 'wrong-type-argument)
63 (should-error (json-serialize '((a . 1) . b)) :type 'wrong-type-argument)
64 (should-error (json-serialize '#1=((a . 1) . #1#)) :type 'circular-list)
65 (should-error (json-serialize '(#1=(a #1#)))))
54 66
55(ert-deftest json-serialize/object-with-duplicate-keys () 67(ert-deftest json-serialize/object-with-duplicate-keys ()
56 (skip-unless (fboundp 'json-serialize)) 68 (skip-unless (fboundp 'json-serialize))