GNU bug report logs -
#15097
24.3.50; json.el can't encode lists of lists
Previous Next
Reported by: Rolando Pereira <rolando_pereira <at> sapo.pt>
Date: Wed, 14 Aug 2013 22:46:02 UTC
Severity: normal
Found in version 24.3.50
Done: Daniel Colascione <dancol <at> dancol.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Glenn Morris <rgm <at> gnu.org> 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]]'
This bug report was last modified 11 years and 65 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.