From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: swedebugia Newsgroups: gmane.lisp.guile.user Subject: Re: help with guile-json inconsistencies Date: Mon, 10 Dec 2018 09:12:47 +0100 Message-ID: <1407eaad-1fc8-f69f-a4dc-949af52ad5c9@riseup.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1544429484 31343 195.159.176.226 (10 Dec 2018 08:11:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2018 08:11:24 +0000 (UTC) To: =?UTF-8?Q?Aleix_Conchillo_Flaqu=c3=a9?= , guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Dec 10 09:11:20 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 1gWGeu-00085V-1Z for guile-user@m.gmane.org; Mon, 10 Dec 2018 09:11:20 +0100 Original-Received: from localhost ([::1]:59689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWGh0-0000mp-4x for guile-user@m.gmane.org; Mon, 10 Dec 2018 03:13:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWGgY-0000eO-Be for guile-user@gnu.org; Mon, 10 Dec 2018 03:13:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWGgU-0002DR-Vh for guile-user@gnu.org; Mon, 10 Dec 2018 03:13:02 -0500 Original-Received: from mx1.riseup.net ([198.252.153.129]:46020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWGgR-00029U-IG for guile-user@gnu.org; Mon, 10 Dec 2018 03:12:57 -0500 Original-Received: from piha.riseup.net (piha-pn.riseup.net [10.0.1.163]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 4FFA61A0585; Mon, 10 Dec 2018 00:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1544429571; bh=ncpmBo/d+5+h7lS0R92Cyr9hR8Iv3ecJ0lT4Vs5E/rE=; h=Subject:To:References:From:Date:In-Reply-To:From; b=InfqF2Uavos1x59Ay57Y/5AlLYbWckgFo2oDM//McQpf0UqAsYDMCxWT8LqmJpDp2 GaBTrvq1ApmsMkFqw1kZkQdzTcTs/8P8Vd5nDaBFdo6iDnd60NVkpyTgkcfGV9RgDj 9bc9HmCO++mai7JSMkvq2fwypRmOeqrM9xiYOy3w= X-Riseup-User-ID: FB294FD33A5ED8338BAB0F376C6F761346BEEB0C70DD9F5881B667DCCA5AD7FD Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by piha.riseup.net with ESMTPSA id 6835B6A38E; Mon, 10 Dec 2018 00:12:50 -0800 (PST) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.252.153.129 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:15039 Archived-At: On 2018-12-10 08:27, Aleix Conchillo Flaqu=C3=A9 wrote: > 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 probabl= y >>> expect [[1,2,3]] >>> (scm->json '((1 2 3) (4 5 6)) it returns {"1":[2,3], "4":[5,6]} bu= t >>> 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). >> >=20 > Answering myself again. Re-adding the macro fixes the issue, but with > a breaking change. >=20 > (scm->json '(1 2 3)) > -> [1,2,3] >=20 > (scm->json '((1 2 3) (4 5 6))) > -> [[1,2,3],[4,5,6]] >=20 > (scm->json (json (object ("key1" "value1") ("key2" (1 2 3))))) > -> {"key2":[1,2,3],"key1":"value1"} >=20 > (scm->json `((1 2 3) ,(json (object (4 5))))) > -> [[1,2,3],{"4":5}] >=20 > So, the (json) macro is only needed to specify JSON objects, otherwise > you can use scheme types directly (and lists are always arrays). Nice to hear you solved it :) Both Guix and guile-wikidata use guile-json but only from json->scm and=20 that works flawlessly. Thanks for creating and maintaining this lib. --=20 Cheers Swedebugia