Function: json-serialize

json-serialize is a function defined in json.c.

Signature

(json-serialize OBJECT &rest ARGS)

Documentation

Return the JSON representation of OBJECT as a unibyte string.

OBJECT is translated as follows:

t -- the JSON true value.
number -- a JSON number.
string -- a JSON string.
vector -- a JSON array.
hash-table -- a JSON object. Keys must be strings.
alist -- a JSON object. Keys must be symbols.
plist -- a JSON object. Keys must be symbols.
              A leading colon in plist key names is elided.

For duplicate object keys, the first value is used.

The Lisp equivalents to the JSON null and false values are configurable in the arguments ARGS, a list of keyword/argument pairs:

:null-object OBJ -- use OBJ to represent a JSON null value.
  It defaults to :null.

:false-object OBJ -- use OBJ to represent a JSON false value.
  It defaults to :false.

In you specify the same value for :null-object and :false-object, a potentially ambiguous situation, the JSON output will not contain any JSON false values.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

// Defined in /usr/src/emacs/src/json.c
{
  specpdl_ref count = SPECPDL_INDEX ();
  json_out_t jo;
  json_serialize (&jo, args[0], nargs - 1, args + 1);
  return unbind_to (count, make_unibyte_string (jo.buf, jo.size));
}