@node Parsing JSON
@section Parsing and generating JSON values
@cindex JSON
+@cindex JavaScript Object Notation
- When Emacs is compiled with JSON support, it provides a couple of
-functions to convert between Lisp objects and JSON values. Any JSON
-value can be converted to a Lisp object, but not vice versa.
-Specifically:
+ When Emacs is compiled with @acronym{JSON} (@dfn{JavaScript Object
+Notation}) support, it provides several functions to convert
+between Lisp objects and JSON values. Any JSON value can be converted
+to a Lisp object, but not vice versa. Specifically:
@itemize
-
@item
JSON uses three keywords: @code{true}, @code{null}, @code{false}.
@code{true} is represented by the symbol @code{t}. By default, the
integers and Lisp floating-point numbers.
@item
-JSON strings are always Unicode strings. Lisp strings can contain
-non-Unicode characters.
+JSON strings are always Unicode strings encoded in UTF-8. Lisp
+strings can contain non-Unicode characters.
@item
JSON has only one sequence type, the array. JSON arrays are
contains several elements with the same key, Emacs uses only the first
element for serialization, in accordance with the behavior of
@code{assq}.
-
@end itemize
@noindent
If some Lisp object can't be represented in JSON, the serialization
functions will signal an error of type @code{wrong-type-argument}.
-The parsing functions will signal the following errors:
+The parsing functions can also signal the following errors:
@table @code
-
@item json-end-of-file
- Signaled when encountering a premature end of the input text.
+Signaled when encountering a premature end of the input text.
@item json-trailing-content
- Signaled when encountering unexpected input after the first JSON
- object parsed.
+Signaled when encountering unexpected input after the first JSON
+object parsed.
@item json-parse-error
- Signaled when encountering invalid JSON syntax.
-
+Signaled when encountering invalid JSON syntax.
@end table
Only top-level values (arrays and objects) can be serialized to
keyword/argument pairs. The following keywords are accepted:
@table @code
-
@item :null-object
The value decides which Lisp object to use to represent the JSON
keyword @code{null}. It defaults to the symbol @code{:null}.
@item :false-object
The value decides which Lisp object to use to represent the JSON
keyword @code{false}. It defaults to the symbol @code{:false}.
-
@end table
@end defun
@defun json-insert object &rest args
This function inserts the JSON representation of @var{object} into the
-current buffer before point. @var{args} is interpreted as in
-@code{json-parse-string}.
+current buffer before point. The argument @var{args} are interpreted
+as in @code{json-parse-string}.
@end defun
@defun json-parse-string string &rest args
pairs. The following keywords are accepted:
@table @code
-
@item :object-type
The value decides which Lisp object to use for representing the
key-value mappings of a JSON object. It can be either
@item :false-object
The value decides which Lisp object to use to represent the JSON
keyword @code{false}. It defaults to the symbol @code{:false}.
-
@end table
@end defun
This function reads the next JSON value from the current buffer,
starting at point. It moves point to the position immediately after
the value if a value could be read and converted to Lisp; otherwise it
-doesn't move point. @var{args} is interpreted as in
+doesn't move point. The arguments @var{args} are interpreted as in
@code{json-parse-string}.
@end defun