From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.user Subject: Re: help with guile-json inconsistencies Date: Sun, 9 Dec 2018 23:27:34 -0800 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1544426764 30109 195.159.176.226 (10 Dec 2018 07:26:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2018 07:26:04 +0000 (UTC) To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Dec 10 08:26:00 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWFx2-0007gk-8v for guile-user@m.gmane.org; Mon, 10 Dec 2018 08:26:00 +0100 Original-Received: from localhost ([::1]:59585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWFz8-0004tP-KT for guile-user@m.gmane.org; Mon, 10 Dec 2018 02:28:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWFym-0004lK-OK for guile-user@gnu.org; Mon, 10 Dec 2018 02:27:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWFyl-0003Z5-Or for guile-user@gnu.org; Mon, 10 Dec 2018 02:27:48 -0500 Original-Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]:33645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWFyl-0003Yd-Gi for guile-user@gnu.org; Mon, 10 Dec 2018 02:27:47 -0500 Original-Received: by mail-lj1-x233.google.com with SMTP id v1-v6so8680667ljd.0 for ; Sun, 09 Dec 2018 23:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=50xIZce3wWN/g3695c3s7gfTTD8JJ5iQ9CzCfLNjVRs=; b=F3+xRDKiDfypB1mYqqTthvzWVrVxxMAyIFW09AlyNFozNN/cqH2G5yy6KBxdWeadrZ gEUAgmtcToIM+A8TBJsioaBuwsR/rLn8MyCz1TFRlsBN3o/Bw8Ad9pMSWiD1vBvjzZc3 jAM5ygOfjVVc5HQiskAfshEq45VVp4uFyPX72DTbxqXrmH1zbIO6lzPM2vB542jGprmf ORq8Dvv7YEsy7jcYdxHf/9LjiuZ5cUvsXPAJetbEuSNQcIqx2+xIbhip4wgJ5RQN5OLC qoJe+GDgmsWn8EWe1g6BERqxjgvePAHwch2ZYcDjmFyr2zuwrVGMDZ6ABppe52KBp/nw G6Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=50xIZce3wWN/g3695c3s7gfTTD8JJ5iQ9CzCfLNjVRs=; b=e+AxJdebX4p2aADFWSI+TzU1VkWRCrvdvF91eMqQGDXWgMl8Np0PdEIpvsCCBaL+be EmHE7t5BB+tHE0ZkWfSNAwBQjO4TEjnawSGjvcx9kCMRf/IBJFi3OniXUrikgdcbsyCZ hgHXHZmGDBquC5IIKyVjBJ9TT7oVNNThwznktzzGGqV5XHJHD/VZ++R86bQ3ITUVX7pT 9MUiluH++YsdzN4lLNYbEgmjgl/Efl7JBWAm0PFfgPaEr54Nu1mMjMtkgmegAD0tJybC T8yOMku8QY3S9dv1ekovBi8sHySjfyryov/Z/A6vdK3b0vD4UHiGovEWePBq2nbrG/hC YXiQ== X-Gm-Message-State: AA+aEWawsyHDXuRHx7ZvesZ589pENxYTK9OahBW2TAvGwEtWNMhVdDe0 n+J/ODH9rYmuzZXCmJlp+vtTv9jKcP8e/DQuQYYXw6QH X-Google-Smtp-Source: AFSGD/WSYfQ9Uo2D2UH397qJzgPhhHwh2tzbKSSsQsuJXCLi79SY8rVmEywZ2nKlN/+jNNK+VpT55HCMIkgM9Mduv6U= X-Received: by 2002:a2e:914b:: with SMTP id q11-v6mr6169603ljg.164.1544426865723; Sun, 09 Dec 2018 23:27:45 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::233 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15038 Archived-At: On Sun, Dec 9, 2018 at 10:33 PM Aleix Conchillo Flaqu=C3=A9 wrote: > > On Sun, Dec 9, 2018 at 2:56 AM Aleix Conchillo Flaqu=C3=A9 > wrote: > > > > Hi guilers, > > > > a new guile-json issue came to me recently: > > > > https://github.com/aconchillo/guile-json/issues/22 > > > > I don't really have a solution yet on how to solve this, so I would > > love some advice. The issue is that one can do: > > > > (scm->json '(1 2 3)) which returns [1,2,3] > > > > however, if you do: > > > > (scm->json '((1 2 3)) it returns {"1":[2,3]} but one would probably > > expect [[1,2,3]] > > (scm->json '((1 2 3) (4 5 6)) it returns {"1":[2,3], "4":[5,6]} but > > one would probably expect [[1,2,3], [4,5,6]] > > > > I guess the first question is, does everyone else feel the same way > > about the return value? > > > > The problem is that there's a function that checks if something is an > > alist by basically checking if it's a pair? recursively and if so, it > > builds a json object. > > > > Just to clarify, the problem is not when parsing JSON to scheme data > types, this is fine as internally guile-json uses hash tables and > lists properly. > > The problem is with going from scheme to json. For convenience, > guile-json doesn't expect a hash table from the user, instead it tries > to guess what's a list and what's an alist however, that seems not > really distinguishable. That is, there's no way to tell if '((1 2)) is > [[1, 2]] or {"1" : [2]} or {"1" : "2"}. > > I guess going back to a macro approach for these type of cases would > help (even though I had the same problem with my initial macro). > Answering myself again. Re-adding the macro fixes the issue, but with a breaking change. (scm->json '(1 2 3)) -> [1,2,3] (scm->json '((1 2 3) (4 5 6))) -> [[1,2,3],[4,5,6]] (scm->json (json (object ("key1" "value1") ("key2" (1 2 3))))) -> {"key2":[1,2,3],"key1":"value1"} (scm->json `((1 2 3) ,(json (object (4 5))))) -> [[1,2,3],{"4":5}] So, the (json) macro is only needed to specify JSON objects, otherwise you can use scheme types directly (and lists are always arrays). Aleix