aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJoão Távora2018-06-02 00:23:38 +0100
committerJoão Távora2018-06-07 12:30:39 +0100
commit3509aaaefe1996ea46b038850629b6d2f7a726fe (patch)
tree651fec98d47d8c77863f6f0b08c9b3c9c6ac2362 /doc
parent2e2f61efa66b69fbd12c83bbd5370a4be2374f66 (diff)
downloademacs-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.texi25
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
5028JSON has only one map type, the object. JSON objects are represented 5028JSON has only one map type, the object. JSON objects are represented
5029using Lisp hashtables or alists. When an alist contains several 5029using Lisp hashtables, alists or plists. When an alist or plist
5030elements with the same key, Emacs uses only the first element for 5030contains several elements with the same key, Emacs uses only the first
5031serialization, in accordance with the behavior of @code{assq}. 5031element 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
5036Note that @code{nil} is a valid alist and represents the empty JSON 5037Note that @code{nil}, being both a valid alist and a valid plist,
5037object, @code{@{@}}, not @code{null}, @code{false}, or an empty array, 5038represents @code{@{@}}, the empty JSON object; not @code{null},
5038all of which are different JSON values. 5039@code{false}, or an empty array, all of which are different JSON
5040values.
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
5041functions will signal an error of type @code{wrong-type-argument}. 5043functions 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
5059JSON. The subobjects within these top-level values can be of any 5061JSON. The subobjects within these top-level values can be of any
5060type. Likewise, the parsing functions will only return vectors, 5062type. Likewise, the parsing functions will only return vectors,
5061hashtables, and alists. 5063hashtables, 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
5064keyword argument, @code{:object-type}, is recognized; its value can be 5066keyword argument, @code{:object-type}, is recognized; its value
5065either @code{hash-table} to parse JSON objects as hashtables with 5067decides which Lisp object to use for representing the key-value
5066string keys (the default) or @code{alist} to parse them as alists. 5068mappings of a JSON object. It can be either @code{hash-table}, the
5069default, to make hashtables with strings as keys, @code{alist} to use
5070alists with symbols as keys or @code{plist} to use plists with keyword
5071symbols as keys.
5067 5072
5068@defun json-serialize object 5073@defun json-serialize object
5069This function returns a new Lisp string which contains the JSON 5074This function returns a new Lisp string which contains the JSON