Skip to content

JSONRPC objects in Elisp

Emacs’s preferred way of representing JSON is via Lisp lists. In Eglot, the syntax of this list is the simplest possible (the one with fewer parenthesis), a plist (see Property Lists in GNU Emacs Lisp Reference Manual).

The plist may be arbitrarily complex, and generally containing other keyword-value property sub-plists corresponding to JSON sub-objects.

For representing the JSON leaf values true, false, null and {}, you can use the Lisp values t, :json-false, nil, and eglot-{}, respectively. JSON arrays are represented as Elisp vectors surrounded by square brackets (see Vectors in GNU Emacs Lisp Reference Manual).

For example, the plist

emacs-lisp
(:pylsp (:plugins (:jedi_completion (:include_params t
                                     :fuzzy t
                                     :cache_for ["pandas" "numpy"])
                   :pylint (:enabled :json-false)))
 :gopls (:usePlaceholders t))

is serialized by Eglot to the following JSON text:

bash
{
  "pylsp": {
    "plugins": {
      "jedi_completion": {
        "include_params": true,
        "fuzzy": true,
        "cache_for": [ "pandas", "numpy" ]
      },
      "pylint": {
        "enabled": false
      }
    }
  },
  "gopls": {
    "usePlaceholders": true
  }
}