bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13518: 24.2; json-encode fails on list-of-alists


From: Simon Schubert
Subject: bug#13518: 24.2; json-encode fails on list-of-alists
Date: Mon, 21 Jan 2013 15:13:30 +0100

json-encode fails to encode a list-of-alists:

(require 'json)
(let* ((mypair (cons 'a 'b))
       (myalist (list mypair))
       (mylistofalist (list myalist)))
  (print (json-encode mylistofalist)))

produces this:

Debugger entered--Lisp error: (wrong-type-argument listp b)
  mapconcat(json-encode (a . b) ", ")
  json-encode-array((a . b))
  json-encode-list((a . b))
  json-encode((a . b))
  #[(cons) "\301\302\303@!\303A!#\207" [cons format "%s:%s" json-encode] 
5](((a . b)))
  mapcar(#[(cons) "\301\302\303@!\303A!#\207" [cons format "%s:%s" 
json-encode] 5] (((a . b))))
  json-encode-alist((((a . b))))
  json-encode-list((((a . b))))
  json-encode((((a . b))))
...


The following function fixes this issue:

(defun json-alist-p (list)
  "Non-null if and only if LIST is an alist with simple keys."
  (while (consp list)
    (setq list (if (and (consp (car list))
                        (atom (caar list)))
                   (cdr list)
                 'not-alist)))
  (null list))


cheers,
  simon





reply via email to

[Prev in Thread] Current Thread [Next in Thread]