diff options
| author | João Távora | 2018-06-07 17:41:19 +0100 |
|---|---|---|
| committer | João Távora | 2018-06-15 00:11:56 +0100 |
| commit | 9348039ed45c8e493e8bfef0220249d4d31ef6da (patch) | |
| tree | e7f79a9013d4b80bfb6b980a216419662f982866 /doc | |
| parent | 8cb9beb32163fa3ce3b052ced646fd673814ddc6 (diff) | |
| download | emacs-9348039ed45c8e493e8bfef0220249d4d31ef6da.tar.gz emacs-9348039ed45c8e493e8bfef0220249d4d31ef6da.zip | |
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.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/text.texi | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 2c5b5a1b42e..5b94580827f 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -5008,9 +5008,10 @@ Specifically: | |||
| 5008 | @itemize | 5008 | @itemize |
| 5009 | 5009 | ||
| 5010 | @item | 5010 | @item |
| 5011 | JSON has a couple of keywords: @code{null}, @code{false}, and | 5011 | JSON uses three keywords: @code{true}, @code{null}, @code{false}. |
| 5012 | @code{true}. These are represented in Lisp using the keywords | 5012 | @code{true} is represented by the symbol @code{t}. By default, the |
| 5013 | @code{:null}, @code{:false}, and @code{t}, respectively. | 5013 | remaining two are represented, respectively, by the symbols |
| 5014 | @code{:null} and @code{:false}. | ||
| 5014 | 5015 | ||
| 5015 | @item | 5016 | @item |
| 5016 | JSON only has floating-point numbers. They can represent both Lisp | 5017 | JSON only has floating-point numbers. They can represent both Lisp |
| @@ -5062,14 +5063,6 @@ JSON. The subobjects within these top-level values can be of any | |||
| 5062 | type. Likewise, the parsing functions will only return vectors, | 5063 | type. Likewise, the parsing functions will only return vectors, |
| 5063 | hashtables, alists, and plists. | 5064 | hashtables, alists, and plists. |
| 5064 | 5065 | ||
| 5065 | The parsing functions accept keyword arguments. Currently only one | ||
| 5066 | keyword argument, @code{:object-type}, is recognized; its value | ||
| 5067 | decides which Lisp object to use for representing the key-value | ||
| 5068 | mappings of a JSON object. It can be either @code{hash-table}, the | ||
| 5069 | default, to make hashtables with strings as keys, @code{alist} to use | ||
| 5070 | alists with symbols as keys or @code{plist} to use plists with keyword | ||
| 5071 | symbols as keys. | ||
| 5072 | |||
| 5073 | @defun json-serialize object | 5066 | @defun json-serialize object |
| 5074 | This function returns a new Lisp string which contains the JSON | 5067 | This function returns a new Lisp string which contains the JSON |
| 5075 | representation of @var{object}. | 5068 | representation of @var{object}. |
| @@ -5080,16 +5073,38 @@ This function inserts the JSON representation of @var{object} into the | |||
| 5080 | current buffer before point. | 5073 | current buffer before point. |
| 5081 | @end defun | 5074 | @end defun |
| 5082 | 5075 | ||
| 5083 | @defun json-parse-string string &key (object-type @code{hash-table}) | 5076 | @defun json-parse-string string &rest args |
| 5084 | This function parses the JSON value in @var{string}, which must be a | 5077 | This function parses the JSON value in @var{string}, which must be a |
| 5085 | Lisp string. | 5078 | Lisp string. The argument @var{args} is a list of keyword/argument |
| 5079 | pairs. The following keywords are accepted: | ||
| 5080 | |||
| 5081 | @itemize | ||
| 5082 | |||
| 5083 | @item @code{:object-type} | ||
| 5084 | The value decides which Lisp object to use for representing the | ||
| 5085 | key-value mappings of a JSON object. It can be either | ||
| 5086 | @code{hash-table}, the default, to make hashtables with strings as | ||
| 5087 | keys; @code{alist} to use alists with symbols as keys; or @code{plist} | ||
| 5088 | to use plists with keyword symbols as keys. | ||
| 5089 | |||
| 5090 | @item @code{:null-object} | ||
| 5091 | The value decides which Lisp object to use to represent the JSON | ||
| 5092 | keyword @code{null}. It defaults to the lisp symbol @code{:null}. | ||
| 5093 | |||
| 5094 | @item @code{:false-object} | ||
| 5095 | The value decides which Lisp object to use to represent the JSON | ||
| 5096 | keyword @code{false}. It defaults to the lisp symbol @code{:false}. | ||
| 5097 | |||
| 5098 | @end itemize | ||
| 5099 | |||
| 5086 | @end defun | 5100 | @end defun |
| 5087 | 5101 | ||
| 5088 | @defun json-parse-buffer &key (object-type @code{hash-table}) | 5102 | @defun json-parse-buffer &rest args |
| 5089 | This function reads the next JSON value from the current buffer, | 5103 | This function reads the next JSON value from the current buffer, |
| 5090 | starting at point. It moves point to the position immediately after | 5104 | starting at point. It moves point to the position immediately after |
| 5091 | the value if a value could be read and converted to Lisp; otherwise it | 5105 | the value if a value could be read and converted to Lisp; otherwise it |
| 5092 | doesn't move point. | 5106 | doesn't move point. @var{args} is interpreted as in |
| 5107 | @code{json-parse-string}. | ||
| 5093 | @end defun | 5108 | @end defun |
| 5094 | 5109 | ||
| 5095 | 5110 | ||