Function: json-read-object

json-read-object is a byte-compiled function defined in json.el.gz.

Signature

(json-read-object)

Documentation

Read the JSON object at point.

Source Code

;; Defined in /usr/src/emacs/lisp/json.el.gz
(defun json-read-object ()
  "Read the JSON object at point."
  ;; Skip over the '{'.
  (json-advance)
  (json-skip-whitespace)
  ;; Read key/value pairs until '}'.
  (let ((elements (json-new-object))
        key value)
    (while (/= (json-peek) ?\})
      (json-skip-whitespace)
      (setq key (json-read-string))
      (json-skip-whitespace)
      (if (= (json-peek) ?:)
          (json-advance)
        (signal 'json-object-format (list ":" (json-peek))))
      (json-skip-whitespace)
      (when json-pre-element-read-function
        (funcall json-pre-element-read-function key))
      (setq value (json-read))
      (when json-post-element-read-function
        (funcall json-post-element-read-function))
      (setq elements (json-add-to-object elements key value))
      (json-skip-whitespace)
      (when (/= (json-peek) ?\})
        (if (= (json-peek) ?,)
            (json-advance)
          (signal 'json-object-format (list "," (json-peek))))))
    ;; Skip over the '}'.
    (json-advance)
    (pcase json-object-type
      ('alist (nreverse elements))
      ('plist (json--plist-nreverse elements))
      (_ elements))))