Subject: bug#15097: 24.3.50; json.el can't encode lists of lists

From: Rolando Pereira <[email-masked]>
Date: Mon, 19 Aug 2013 23:09:19 +0100

Glenn Morris <[email-masked]> writes:

> Rolando Pereira wrote:
>
>> The function `json-encode' can't encode a list thats composed only of other
>> lists, i.e. the following doesn't work:
>>
>>     (json-encode '((1 2 3))) => Error: (json-key-format 1)
> [...]
>> (ert-should (string= (json-encode '((1 2 3))) "[[1,2,3]]")) ; doesn't work
>
> I have no idea what this stuff is supposed to do, but by inspection it
> treats such arguments as alists and requires that the key be encodable
> as a string. Eg this works
>
> (json-encode '((a 2 3)))   ->    "{\"a\":[2, 3]}"
>
> Your example fails because 1 is encoded as 1, not "1".
>
> Should the answer be "{\"1\":[2, 3]} or "[[1,2,3]]"?

Personally I was expecting the answer to be "[[1,2,3]]" i.e. turn the
'(1 2 3) list into a list and not an object.

Which, for the purposes of comparison, is similar to what the Lisp
library "cl-json" and the Python "json" library do:

* Common Lisp

CL-USER> (ql:quickload 'cl-json)
[...snip...]
CL-USER> (cl-json:encode-json '((1 2 3)))
[[1,2,3]]
NIL
CL-USER>

* Python

Python 2.7.3 (default, Aug  1 2012, 05:16:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.dumps([[1,2,3]])
'[[1, 2, 3]]'