* bug#15097: 24.3.50; json.el can't encode lists of lists
@ 2013-08-14 22:44 Rolando Pereira
2013-08-15 1:55 ` Glenn Morris
2014-03-23 6:40 ` bug#15097: Wontfix, apparently Daniel Colascione
0 siblings, 2 replies; 7+ messages in thread
From: Rolando Pereira @ 2013-08-14 22:44 UTC (permalink / raw
To: 15097
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: 24.3.50; json.el can't encode lists of lists
2013-08-14 22:44 bug#15097: 24.3.50; json.el can't encode lists of lists Rolando Pereira
@ 2013-08-15 1:55 ` Glenn Morris
2013-08-19 22:09 ` Rolando Pereira
2013-08-19 22:09 ` Rolando Pereira
2014-03-23 6:40 ` bug#15097: Wontfix, apparently Daniel Colascione
1 sibling, 2 replies; 7+ messages in thread
From: Glenn Morris @ 2013-08-15 1:55 UTC (permalink / raw
To: Rolando Pereira; +Cc: 15097
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]]"?
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: 24.3.50; json.el can't encode lists of lists
2013-08-15 1:55 ` Glenn Morris
@ 2013-08-19 22:09 ` Rolando Pereira
2013-08-19 22:09 ` Rolando Pereira
1 sibling, 0 replies; 7+ messages in thread
From: Rolando Pereira @ 2013-08-19 22:09 UTC (permalink / raw
To: Glenn Morris; +Cc: Rolando Pereira, 15097
Glenn Morris <rgm@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]]'
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: 24.3.50; json.el can't encode lists of lists
2013-08-15 1:55 ` Glenn Morris
2013-08-19 22:09 ` Rolando Pereira
@ 2013-08-19 22:09 ` Rolando Pereira
2013-08-20 17:04 ` Glenn Morris
1 sibling, 1 reply; 7+ messages in thread
From: Rolando Pereira @ 2013-08-19 22:09 UTC (permalink / raw
To: Glenn Morris; +Cc: Rolando Pereira, 15097
Glenn Morris <rgm@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]]'
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: 24.3.50; json.el can't encode lists of lists
2013-08-19 22:09 ` Rolando Pereira
@ 2013-08-20 17:04 ` Glenn Morris
2013-08-20 20:16 ` Edward O'Connor
0 siblings, 1 reply; 7+ messages in thread
From: Glenn Morris @ 2013-08-20 17:04 UTC (permalink / raw
To: Rolando Pereira; +Cc: 15097, Edward O'Connor
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 )
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: 24.3.50; json.el can't encode lists of lists
2013-08-20 17:04 ` Glenn Morris
@ 2013-08-20 20:16 ` Edward O'Connor
0 siblings, 0 replies; 7+ messages in thread
From: Edward O'Connor @ 2013-08-20 20:16 UTC (permalink / raw
To: Glenn Morris; +Cc: Rolando Pereira, 15097
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@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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#15097: Wontfix, apparently
2013-08-14 22:44 bug#15097: 24.3.50; json.el can't encode lists of lists Rolando Pereira
2013-08-15 1:55 ` Glenn Morris
@ 2014-03-23 6:40 ` Daniel Colascione
1 sibling, 0 replies; 7+ messages in thread
From: Daniel Colascione @ 2014-03-23 6:40 UTC (permalink / raw
To: 15097-done
[-- Attachment #1: Type: text/plain, Size: 35 bytes --]
Wontfix according to discussion
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 901 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-03-23 6:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-14 22:44 bug#15097: 24.3.50; json.el can't encode lists of lists Rolando Pereira
2013-08-15 1:55 ` Glenn Morris
2013-08-19 22:09 ` Rolando Pereira
2013-08-19 22:09 ` Rolando Pereira
2013-08-20 17:04 ` Glenn Morris
2013-08-20 20:16 ` Edward O'Connor
2014-03-23 6:40 ` bug#15097: Wontfix, apparently Daniel Colascione
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.