GNU bug report logs - #15097
24.3.50; json.el can't encode lists of lists

Previous Next

Package: emacs;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15097 in the body.
You can then email your comments to 15097 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Wed, 14 Aug 2013 22:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rolando Pereira <rolando_pereira <at> sapo.pt>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 14 Aug 2013 22:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rolando Pereira <rolando_pereira <at> sapo.pt>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; json.el can't encode lists of lists
Date: Wed, 14 Aug 2013 23:44:36 +0100
Hello all,

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)

If I had an extra "nil" in the topmost list `json-encode' then it works
fine:

    (json-encode '((1 2 3) nil)) => "[[1,2,3],null]"

However if I replace the `nil' with another list then I get the same
error:

    (json-encode '((1 2 3) (4))) => Error: (json-key-format 1)

Here's a small ERT test that should trigger the bug:

    (ert-deftest json-encode-list-of-lists-test ()
      (ert-should (string= (json-encode '(1 2 3)) "[1,2,3]"))              ; works
      (ert-should (string= (json-encode '((1) 2 3)) "[[1],2,3]"))          ; works
      (ert-should (string= (json-encode '((1 2 3))) "[[1,2,3]]"))          ; doesn't work
      (ert-should (string= (json-encode '((1 2 3) nil)) "[[1,2,3],null]")) ; works
      (ert-should (string= (json-encode '((1 2 3) (4))) "[[1,2,3],[4]]"))  ; doesn't work
      )


Best regards,
Rolando Pereira




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Thu, 15 Aug 2013 01:56:01 GMT) Full text and rfc822 format available.

Message #8 received at 15097 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Rolando Pereira <rolando_pereira <at> sapo.pt>
Cc: 15097 <at> debbugs.gnu.org
Subject: Re: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Wed, 14 Aug 2013 21:55:50 -0400
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]]"?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Mon, 19 Aug 2013 22:10:02 GMT) Full text and rfc822 format available.

Message #11 received at 15097 <at> debbugs.gnu.org (full text, mbox):

From: Rolando Pereira <rolando_pereira <at> sapo.pt>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Rolando Pereira <rolando_pereira <at> sapo.pt>, 15097 <at> debbugs.gnu.org
Subject: Re: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Mon, 19 Aug 2013 23:09:10 +0100
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]]"?

0Personally 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]]'




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Mon, 19 Aug 2013 22:10:03 GMT) Full text and rfc822 format available.

Message #14 received at 15097 <at> debbugs.gnu.org (full text, mbox):

From: Rolando Pereira <rolando_pereira <at> sapo.pt>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Rolando Pereira <rolando_pereira <at> sapo.pt>, 15097 <at> debbugs.gnu.org
Subject: Re: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Mon, 19 Aug 2013 23:09:19 +0100
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]]'




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Tue, 20 Aug 2013 17:05:01 GMT) Full text and rfc822 format available.

Message #17 received at 15097 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Rolando Pereira <rolando_pereira <at> sapo.pt>
Cc: 15097 <at> debbugs.gnu.org, Edward O'Connor <hober0 <at> gmail.com>
Subject: Re: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Tue, 20 Aug 2013 13:04:31 -0400
Rolando Pereira wrote:

> 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]]'

Well, maybe that's the actual issue, since json.el and the python
version apparently disagree about what to do in such cases. Eg:

(json-encode '(("a" 2 3)))  ->  "{\"a\":[2, 3]}"
json.dumps([["a",2,3]])     ->  [["a", 2, 3]]


(Context is at http://debbugs.gnu.org/15097 )





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15097; Package emacs. (Tue, 20 Aug 2013 20:17:01 GMT) Full text and rfc822 format available.

Message #20 received at 15097 <at> debbugs.gnu.org (full text, mbox):

From: "Edward O'Connor" <hober0 <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: Rolando Pereira <rolando_pereira <at> sapo.pt>, 15097 <at> debbugs.gnu.org
Subject: Re: bug#15097: 24.3.50; json.el can't encode lists of lists
Date: Tue, 20 Aug 2013 13:16:25 -0700
The basic problem is that (("a" 1 2)) is the same thing as (("a" . (1
2))). Is that a list of one three-item list, or is it an alist with
one entry, whose key is "a" and whose value is a two-item list? It
might be reasonable for `json-encode-list' to provide programmatic
control over this, but the current behavior isn't a bug.

On Tue, Aug 20, 2013 at 10:04 AM, Glenn Morris <rgm <at> gnu.org> wrote:
> Rolando Pereira wrote:
>
>> 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]]'
>
> Well, maybe that's the actual issue, since json.el and the python
> version apparently disagree about what to do in such cases. Eg:
>
> (json-encode '(("a" 2 3)))  ->  "{\"a\":[2, 3]}"
> json.dumps([["a",2,3]])     ->  [["a", 2, 3]]
>
>
> (Context is at http://debbugs.gnu.org/15097 )
>



-- 
Edward O'Connor




Reply sent to Daniel Colascione <dancol <at> dancol.org>:
You have taken responsibility. (Sun, 23 Mar 2014 06:41:02 GMT) Full text and rfc822 format available.

Notification sent to Rolando Pereira <rolando_pereira <at> sapo.pt>:
bug acknowledged by developer. (Sun, 23 Mar 2014 06:41:04 GMT) Full text and rfc822 format available.

Message #25 received at 15097-done <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: 15097-done <at> debbugs.gnu.org
Subject: Wontfix, apparently
Date: Sat, 22 Mar 2014 23:40:19 -0700
[Message part 1 (text/plain, inline)]
Wontfix according to discussion

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 20 Apr 2014 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.