--- Begin Message ---
Subject: |
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) "address@hidden" [cons format "%s:%s" json-encode] 5](((a . b)))
mapcar(#[(cons) "address@hidden" [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
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#13518: 24.2; json-encode fails on list-of-alists |
Date: |
Mon, 25 Nov 2013 00:57:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Version: 24.4
Simon Schubert <address@hidden> writes:
> 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))
Applied, thanks!
--- End Message ---