From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rolando Pereira Newsgroups: gmane.emacs.bugs Subject: bug#15097: 24.3.50; json.el can't encode lists of lists Date: Mon, 19 Aug 2013 23:09:19 +0100 Message-ID: <87d2p9coz4.fsf@sapo.pt> References: <87pptf7uzv.fsf@sapo.pt> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1376950222 22143 80.91.229.3 (19 Aug 2013 22:10:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 19 Aug 2013 22:10:22 +0000 (UTC) Cc: Rolando Pereira , 15097@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 20 00:10:23 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VBXeW-0000lJ-MU for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Aug 2013 00:10:20 +0200 Original-Received: from localhost ([::1]:45046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VBXeW-000743-6w for geb-bug-gnu-emacs@m.gmane.org; Mon, 19 Aug 2013 18:10:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VBXeN-00072f-5H for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2013 18:10:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VBXeH-0001hu-B9 for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2013 18:10:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VBXeH-0001hU-8X for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2013 18:10:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VBXeF-0003ZV-QV for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2013 18:10:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Rolando Pereira Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Aug 2013 22:10:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15097 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15097-submit@debbugs.gnu.org id=B15097.137695017213679 (code B ref 15097); Mon, 19 Aug 2013 22:10:03 +0000 Original-Received: (at 15097) by debbugs.gnu.org; 19 Aug 2013 22:09:32 +0000 Original-Received: from localhost ([127.0.0.1]:41165 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VBXdj-0003YW-Gp for submit@debbugs.gnu.org; Mon, 19 Aug 2013 18:09:32 -0400 Original-Received: from relay2.ptmail.sapo.pt ([212.55.154.22]:36635 helo=sapo.pt) by debbugs.gnu.org with smtp (Exim 4.80) (envelope-from ) id 1VBXdc-0003YJ-Nj for 15097@debbugs.gnu.org; Mon, 19 Aug 2013 18:09:25 -0400 Original-Received: (qmail 25827 invoked from network); 19 Aug 2013 22:09:22 -0000 Original-Received: from unknown (HELO sapo.pt) (10.134.37.165) by relay2 with SMTP; 19 Aug 2013 22:09:22 -0000 Original-Received: (qmail 20567 invoked from network); 19 Aug 2013 22:09:22 -0000 Original-Received: from unknown (HELO rolando-K8NF4G-VSTA) (finalyugi@sapo.pt@[188.80.62.180]) (envelope-sender ) by mta15 (qmail-ptmail-1.0.0) with AES128-SHA encrypted SMTP for <15097@debbugs.gnu.org>; 19 Aug 2013 22:09:21 -0000 In-Reply-To: (Glenn Morris's message of "Wed, 14 Aug 2013 21:55:50 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:77527 Archived-At: Glenn Morris 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]]'