From 9348039ed45c8e493e8bfef0220249d4d31ef6da Mon Sep 17 00:00:00 2001 From: João Távora Date: Thu, 7 Jun 2018 17:41:19 +0100 Subject: 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. --- test/src/json-tests.el | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/src') diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 7a193545b1a..918b2336d0f 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el @@ -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 -- cgit v1.2.1