Function: json-add-to-object

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

Signature

(json-add-to-object OBJECT KEY VALUE)

Documentation

Add a new KEY -> VALUE association to OBJECT.

Returns the updated object, which you should save, e.g.:
    (setq obj (json-add-to-object obj "foo" "bar"))
Please see the documentation of json-object-type and json-key-type.

Source Code

;; Defined in /usr/src/emacs/lisp/json.el.gz
(defun json-add-to-object (object key value)
  "Add a new KEY -> VALUE association to OBJECT.
Returns the updated object, which you should save, e.g.:
    (setq obj (json-add-to-object obj \"foo\" \"bar\"))
Please see the documentation of `json-object-type' and `json-key-type'."
  (let ((json-key-type
         (cond (json-key-type)
               ((eq json-object-type 'hash-table) 'string)
               ((eq json-object-type 'alist)      'symbol)
               ((eq json-object-type 'plist)      'keyword))))
    (setq key
          (cond ((eq json-key-type 'string)
                 key)
                ((eq json-key-type 'symbol)
                 (intern key))
                ((eq json-key-type 'keyword)
                 (intern (concat ":" key)))))
    (cond ((eq json-object-type 'hash-table)
           (puthash key value object)
           object)
          ((eq json-object-type 'alist)
           (cons (cons key value) object))
          ((eq json-object-type 'plist)
           (cons key (cons value object))))))