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

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

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


From: Rolando Pereira
Subject: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Mon, 19 Aug 2013 23:09:19 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Glenn Morris <address@hidden> 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]]'





reply via email to

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