unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13518: 24.2; json-encode fails on list-of-alists
@ 2013-01-21 14:13 Simon Schubert
  2013-11-24 22:57 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Schubert @ 2013-01-21 14:13 UTC (permalink / raw)
  To: 13518

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\b@!\303\bA!#\207" [cons format "%s:%s" json-encode] 5](((a . b)))
  mapcar(#[(cons) "\301\302\303\b@!\303\bA!#\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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#13518: 24.2; json-encode fails on list-of-alists
  2013-01-21 14:13 bug#13518: 24.2; json-encode fails on list-of-alists Simon Schubert
@ 2013-11-24 22:57 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2013-11-24 22:57 UTC (permalink / raw)
  To: Simon Schubert; +Cc: 13518-done

Version: 24.4

Simon Schubert <2@0x2c.org> 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!





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-24 22:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-21 14:13 bug#13518: 24.2; json-encode fails on list-of-alists Simon Schubert
2013-11-24 22:57 ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).