diff options
| author | João Távora | 2018-06-02 00:23:38 +0100 |
|---|---|---|
| committer | João Távora | 2018-06-07 12:30:39 +0100 |
| commit | 3509aaaefe1996ea46b038850629b6d2f7a726fe (patch) | |
| tree | 651fec98d47d8c77863f6f0b08c9b3c9c6ac2362 /doc | |
| parent | 2e2f61efa66b69fbd12c83bbd5370a4be2374f66 (diff) | |
| download | emacs-3509aaaefe1996ea46b038850629b6d2f7a726fe.tar.gz emacs-3509aaaefe1996ea46b038850629b6d2f7a726fe.zip | |
Accept plists when serializing and parsing JSON
* doc/lispref/text.texi (Parsing JSON): Mention plist support.
* src/json.c (lisp_to_json_toplevel_1): Serialize plists to json.
(Fjson_serialize): Mention plists in docstring.
(enum json_object_type): Add json_object_plist.
(json_to_lisp): Parse JSON into plists.
(json_parse_object_type): Consider plists.
(Fjson_parse_string): Mention plists in docstring.
(syms_of_json): New Qplist sym_of_json.
(lisp_to_json): Update comment.
* test/src/json-tests.el (json-serialize/object)
(json-parse-string/object): New plist tests.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/text.texi | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 2afcd59a706..2c5b5a1b42e 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -5026,16 +5026,18 @@ represented using Lisp vectors. | |||
| 5026 | 5026 | ||
| 5027 | @item | 5027 | @item |
| 5028 | JSON has only one map type, the object. JSON objects are represented | 5028 | JSON has only one map type, the object. JSON objects are represented |
| 5029 | using Lisp hashtables or alists. When an alist contains several | 5029 | using Lisp hashtables, alists or plists. When an alist or plist |
| 5030 | elements with the same key, Emacs uses only the first element for | 5030 | contains several elements with the same key, Emacs uses only the first |
| 5031 | serialization, in accordance with the behavior of @code{assq}. | 5031 | element for serialization, in accordance with the behavior of |
| 5032 | @code{assq}. | ||
| 5032 | 5033 | ||
| 5033 | @end itemize | 5034 | @end itemize |
| 5034 | 5035 | ||
| 5035 | @noindent | 5036 | @noindent |
| 5036 | Note that @code{nil} is a valid alist and represents the empty JSON | 5037 | Note that @code{nil}, being both a valid alist and a valid plist, |
| 5037 | object, @code{@{@}}, not @code{null}, @code{false}, or an empty array, | 5038 | represents @code{@{@}}, the empty JSON object; not @code{null}, |
| 5038 | all of which are different JSON values. | 5039 | @code{false}, or an empty array, all of which are different JSON |
| 5040 | values. | ||
| 5039 | 5041 | ||
| 5040 | If some Lisp object can't be represented in JSON, the serialization | 5042 | If some Lisp object can't be represented in JSON, the serialization |
| 5041 | functions will signal an error of type @code{wrong-type-argument}. | 5043 | functions will signal an error of type @code{wrong-type-argument}. |
| @@ -5058,12 +5060,15 @@ The parsing functions will signal the following errors: | |||
| 5058 | Only top-level values (arrays and objects) can be serialized to | 5060 | Only top-level values (arrays and objects) can be serialized to |
| 5059 | JSON. The subobjects within these top-level values can be of any | 5061 | JSON. The subobjects within these top-level values can be of any |
| 5060 | type. Likewise, the parsing functions will only return vectors, | 5062 | type. Likewise, the parsing functions will only return vectors, |
| 5061 | hashtables, and alists. | 5063 | hashtables, alists, and plists. |
| 5062 | 5064 | ||
| 5063 | The parsing functions accept keyword arguments. Currently only one | 5065 | The parsing functions accept keyword arguments. Currently only one |
| 5064 | keyword argument, @code{:object-type}, is recognized; its value can be | 5066 | keyword argument, @code{:object-type}, is recognized; its value |
| 5065 | either @code{hash-table} to parse JSON objects as hashtables with | 5067 | decides which Lisp object to use for representing the key-value |
| 5066 | string keys (the default) or @code{alist} to parse them as alists. | 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. | ||
| 5067 | 5072 | ||
| 5068 | @defun json-serialize object | 5073 | @defun json-serialize object |
| 5069 | This function returns a new Lisp string which contains the JSON | 5074 | This function returns a new Lisp string which contains the JSON |