mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-27 07:41:28 -08:00
Support custom null and false objects when parsing JSON
* doc/lispref/text.texi (Parsing JSON): Describe new :null-object and :false-object kwargs to json-parse-string and json-parse-buffer. * src/json.c (struct json_configuration): New type. (json_to_lisp): Accept a struct json_configuration* param. (json_parse_args): Rename from json_parse_object_type. (Fjson_parse_string): Rework docstring. (Fjson_parse_string, Fjson_parse_buffer): Update call to json_to_lisp. (syms_of_json): Two new syms, QCnull_object and QCfalse_object. * test/src/json-tests.el (json-parse-with-custom-null-and-false-objects): New test.
This commit is contained in:
parent
8cb9beb321
commit
9348039ed4
3 changed files with 140 additions and 68 deletions
|
|
@ -209,6 +209,35 @@ Test with both unibyte and multibyte strings."
|
|||
(should-not (bobp))
|
||||
(should (looking-at-p (rx " [456]" eos)))))
|
||||
|
||||
(ert-deftest json-parse-with-custom-null-and-false-objects ()
|
||||
(let ((input
|
||||
"{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n"))
|
||||
(should (equal (json-parse-string input
|
||||
:object-type 'plist
|
||||
:null-object :json-null
|
||||
:false-object :json-false)
|
||||
'(:abc [9 :json-false] :def :json-null)))
|
||||
(should (equal (json-parse-string input
|
||||
:object-type 'plist
|
||||
:false-object :json-false)
|
||||
'(:abc [9 :json-false] :def :null)))
|
||||
(should (equal (json-parse-string input
|
||||
:object-type 'alist
|
||||
:null-object :zilch)
|
||||
'((abc . [9 :false]) (def . :zilch))))
|
||||
(should (equal (json-parse-string input
|
||||
:object-type 'alist
|
||||
:false-object nil
|
||||
:null-object nil)
|
||||
'((abc . [9 nil]) (def))))
|
||||
(let* ((thingy '(1 2 3))
|
||||
(retval (json-parse-string input
|
||||
:object-type 'alist
|
||||
:false-object thingy
|
||||
:null-object nil)))
|
||||
(should (equal retval `((abc . [9 ,thingy]) (def))))
|
||||
(should (eq (elt (cdr (car retval)) 1) thingy)))))
|
||||
|
||||
(ert-deftest json-insert/signal ()
|
||||
(skip-unless (fboundp 'json-insert))
|
||||
(with-temp-buffer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue