diff options
| author | Philipp Stephani | 2017-12-13 23:35:07 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2017-12-19 18:20:55 +0100 |
| commit | db4f12e93f466832a5e5e1d512aff87ea90ef197 (patch) | |
| tree | 585a95c4cfb8cf765e8df7dc0fe623ed786b6444 /test | |
| parent | 16813e6faa32b1741685ee429132251846d253a3 (diff) | |
| download | emacs-db4f12e93f466832a5e5e1d512aff87ea90ef197.tar.gz emacs-db4f12e93f466832a5e5e1d512aff87ea90ef197.zip | |
Allow JSON parser functions to return alists
* src/json.c (Fjson_parse_string, Fjson_parse_buffer): Give these
functions a keyword argument to specify the return type for JSON
objects.
(json_to_lisp): Convert objects to alists if requested.
(json_parse_object_type): New helper function to parse keyword
arguments.
* test/src/json-tests.el (json-parse-string/object): Add a unit test.
* doc/lispref/text.texi (Parsing JSON): Document new functionality.
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/json-tests.el | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 551f8ac5fe4..100bf7bd39b 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -54,13 +54,15 @@ | |||
| 54 | 54 | ||
| 55 | (ert-deftest json-parse-string/object () | 55 | (ert-deftest json-parse-string/object () |
| 56 | (skip-unless (fboundp 'json-parse-string)) | 56 | (skip-unless (fboundp 'json-parse-string)) |
| 57 | (let ((actual | 57 | (let ((input |
| 58 | (json-parse-string | 58 | "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n")) |
| 59 | "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n"))) | 59 | (let ((actual (json-parse-string input))) |
| 60 | (should (hash-table-p actual)) | 60 | (should (hash-table-p actual)) |
| 61 | (should (equal (hash-table-count actual) 2)) | 61 | (should (equal (hash-table-count actual) 2)) |
| 62 | (should (equal (cl-sort (map-pairs actual) #'string< :key #'car) | 62 | (should (equal (cl-sort (map-pairs actual) #'string< :key #'car) |
| 63 | '(("abc" . [9 :false]) ("def" . :null)))))) | 63 | '(("abc" . [9 :false]) ("def" . :null))))) |
| 64 | (should (equal (json-parse-string input :object-type 'alist) | ||
| 65 | '((abc . [9 :false]) (def . :null)))))) | ||
| 64 | 66 | ||
| 65 | (ert-deftest json-parse-string/string () | 67 | (ert-deftest json-parse-string/string () |
| 66 | (skip-unless (fboundp 'json-parse-string)) | 68 | (skip-unless (fboundp 'json-parse-string)) |