/* We can't specify the length, so the string must be
null-terminated. */
check_string_without_embedded_nulls (key);
- int status = json_object_set_new (*json, SSDATA (key),
+ const char *key_str = SSDATA (key);
+ /* Reject duplicate keys. These are possible if the hash
+ table test is not `equal'. */
+ if (json_object_get (*json, key_str) != NULL)
+ wrong_type_argument (Qjson_value_p, lisp);
+ int status = json_object_set_new (*json, key_str,
lisp_to_json (HASH_VALUE (h, i)));
if (status == -1)
/* FIXME: A failure here might also indicate that the
(should (equal (json-serialize table)
"{\"abc\":[1,2,true],\"def\":null}"))))
+(ert-deftest json-serialize/object-with-duplicate-keys ()
+ (skip-unless (fboundp 'json-serialize))
+ (let ((table (make-hash-table :test #'eq)))
+ (puthash (copy-sequence "abc") [1 2 t] table)
+ (puthash (copy-sequence "abc") :null table)
+ (should (equal (hash-table-count table) 2))
+ (should-error (json-serialize table) :type 'wrong-type-argument)))
+
(ert-deftest json-parse-string/object ()
(skip-unless (fboundp 'json-parse-string))
(let ((input