GNU bug report logs - #42545
json-encode-key can't handle boolean values

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Marcelo Muñoz <ma.munoz.araya@HIDDEN>; dated Sun, 26 Jul 2020 08:16:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug Marked as found in versions 24.5. Request was from "Basil L. Contovounesios" <contovob@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Changed bug title to 'json-encode-key can't handle boolean values' from '28.0.50; json-pretty-print cant't handle json having "t" as a key' Request was from "Basil L. Contovounesios" <contovob@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 42545 <at> debbugs.gnu.org:


Received: (at 42545) by debbugs.gnu.org; 26 Jul 2020 10:39:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jul 26 06:39:11 2020
Received: from localhost ([127.0.0.1]:51839 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jze3j-0006Z2-Av
	for submit <at> debbugs.gnu.org; Sun, 26 Jul 2020 06:39:11 -0400
Received: from mail-wm1-f47.google.com ([209.85.128.47]:37914)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <contovob@HIDDEN>) id 1jze3g-0006Yj-N8
 for 42545 <at> debbugs.gnu.org; Sun, 26 Jul 2020 06:39:09 -0400
Received: by mail-wm1-f47.google.com with SMTP id f18so11985537wml.3
 for <42545 <at> debbugs.gnu.org>; Sun, 26 Jul 2020 03:39:08 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=tcd-ie.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=Jw4Ht0iGbrqAI0G9+Q8ImNeDLhZWSbO7Q82J9EBMubA=;
 b=V1dd8mu/pTvR/EnvSyNcSp3MVyfGQfwuyi751TLeUNkarZ0c6YGSHDSLpXwYtasxu+
 sBJn78mskU/G552mXOYoTAISFKi14gqNLwfWcRl3gIOiYZ/n6rQ2QeC8U5XG7Kdovj7e
 bvQR2x8vygqRAqrgFymgcp2BA2InhjgXrRHSvNNHC3uYIVbz5h/lg2ZAKQkl84pGb9Ik
 DJimEHDPWQeDd7T9OGR/R30VTqknOAPh3Iwgj3U4wFpx2X33nvhYHAbvnu1NXpOvzXDB
 AACbv/9DkecfyBPM3tIrG5kMizqaClZBgYw8n9cRmkeBiwngqoUI5S8wFL/Tmy27WFfl
 f6EA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version:content-transfer-encoding;
 bh=Jw4Ht0iGbrqAI0G9+Q8ImNeDLhZWSbO7Q82J9EBMubA=;
 b=gV3L1KcpMKckrZ2YMGHMRbQ3ismT1fr007x6TLwkeKJGjqpA9c/zbzb+/bJRjk2PTV
 jgKxU5TQLWo6tpPU3y97f7aTB7ZPZO/sU36ihw0yO95cKecMQCEu1OIS+zl/62qdZ/dY
 rh+IdCAOh+vomhChxakR/GBZJgaSH5UDGdzl/pAD+IfAxx3P0GFUYq9xpe3dxw9mQB6r
 DFD/Lve6C7HVVt7Zw+jsuIw4LEnZgy3IqP97H91swFino0Zoe2Qka7bld7OVt0FN/Fbx
 lau0cY8GCZ+CnKt/ZtU6s75NX5F+pXjQVwzHnu+NJQVaaA8VP72LuVhlrx1We7TIAOH0
 w0OQ==
X-Gm-Message-State: AOAM533IdGackUKynv99caKH6gEos4KL6iP0CtYosq+FxsctxjLWmhZS
 DIMSVbR6x7BbUturJzVUoeNPKg==
X-Google-Smtp-Source: ABdhPJx5XPxMmwq+gb88urrLGSvPXUB9NfA+q/wGNRRaSGeX0mHzYWduTPxPQRbfO4MFFjVuhuC1Qg==
X-Received: by 2002:a1c:2d91:: with SMTP id t139mr15814682wmt.3.1595759942801; 
 Sun, 26 Jul 2020 03:39:02 -0700 (PDT)
Received: from localhost ([80.233.33.180])
 by smtp.gmail.com with ESMTPSA id j5sm4833760wmb.12.2020.07.26.03.39.01
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 26 Jul 2020 03:39:02 -0700 (PDT)
From: "Basil L. Contovounesios" <contovob@HIDDEN>
To: Marcelo =?utf-8?Q?Mu=C3=B1oz?= <ma.munoz.araya@HIDDEN>
Subject: Re: bug#42545: 28.0.50; json-pretty-print cant't handle json having
 "t" as a key
References: <CA+VWJeJs0bsJvOfXrft1Ct+tO5CXvusi6Q-_pGZJFXL2pBH8Bw@HIDDEN>
Date: Sun, 26 Jul 2020 13:38:59 +0300
In-Reply-To: <CA+VWJeJs0bsJvOfXrft1Ct+tO5CXvusi6Q-_pGZJFXL2pBH8Bw@HIDDEN>
 ("Marcelo =?utf-8?Q?Mu=C3=B1oz=22's?= message of "Sun, 26 Jul 2020 02:13:09
 -0400")
Message-ID: <87d04imugs.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 42545
Cc: 42545 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

retitle 42545 json-encode-key can't handle boolean values
found 42545 24.5
quit

Marcelo Mu=C3=B1oz <ma.munoz.araya@HIDDEN> writes:

> Try to apply json-pretty-print to follow json:
>
> {"t": 1, "key":2}
>
> fail with the message:  json-pretty-print: Bad JSON object key: t

Here are some simpler repros:

(json-encode '((nil . 0)))
(json-encode '((t . 0)))
(json-encode-key nil)
(json-encode-key t)

All of these fail with json-key-format since at least as far back as
Emacs 24.5.

> Some research point me the problem is in the function json-encode-key,
> its  implementation is:
>
> (defun json-encode-key (object)
>   "Return a JSON representation of OBJECT.
> If the resulting JSON object isn't a valid JSON object key,
> this signals `json-key-format'."
>   (let ((encoded (json-encode object)))
>     (unless (stringp (json-read-from-string encoded))
>       (signal 'json-key-format (list object)))
>     encoded))
>
> The follow change seems to  solve the problem, but I haven't had time
> understand it in depth:
>
> (defun json-encode-key (object)
>    "Return s string representation of a key"
>    (json-encode-string (symbol-name object)))

This can't be TRT, because OBJECT is not always a symbol.

See also https://debbugs.gnu.org/24252#26 for some precedent in
rewriting json-encode-key without relying on json-encode.

I'm AFK until start of August, but I'll try to have a better look at
this when I get the chance if no-one beats me to it.

Thanks,

--=20
Basil




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#42545; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 26 Jul 2020 08:15:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jul 26 04:15:07 2020
Received: from localhost ([127.0.0.1]:51668 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jzboH-0002zs-4y
	for submit <at> debbugs.gnu.org; Sun, 26 Jul 2020 04:15:07 -0400
Received: from lists.gnu.org ([209.51.188.17]:56604)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ma.munoz.araya@HIDDEN>) id 1jzZuc-0000Ad-98
 for submit <at> debbugs.gnu.org; Sun, 26 Jul 2020 02:13:33 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:48520)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ma.munoz.araya@HIDDEN>)
 id 1jzZuc-00063E-1P
 for bug-gnu-emacs@HIDDEN; Sun, 26 Jul 2020 02:13:30 -0400
Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:43500)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <ma.munoz.araya@HIDDEN>)
 id 1jzZua-0007KQ-FV
 for bug-gnu-emacs@HIDDEN; Sun, 26 Jul 2020 02:13:29 -0400
Received: by mail-io1-xd36.google.com with SMTP id k23so13763907iom.10
 for <bug-gnu-emacs@HIDDEN>; Sat, 25 Jul 2020 23:13:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=qTIL3ASq+rlTtqjbtPifnajYOc1gsNvoX0v54/+GgME=;
 b=chmjIpNIoPVwWH5QFTHPQbwfrnwkzzrxueCRusy5m7K9RbpOih2IytMzcIog0rZP9I
 nE1QATw1K6uzOHsw8JKmvDyyRYh4JQOGLFxoZZrlzVFPl2Zz4pvcqY1K1AnY381tjjTO
 XoY0uuJ53z8c1C6cBnG+SgkSr0g1VzZU/6rMwAcnRHhsQoffCKBiek6tV07wbWR1wBhT
 eozbr09oLnS+bs5dFjKqB3l5nCVVxnv1TiYIC5EwgnnPhnPO7ZGIDgUQD0+0BKf+rhUY
 H4n5EKWL5mbzcj4P16ROnCADleNAmrt2KiQecWOoum3JJ/wLnf8WYr0u1SDGiE31F8w/
 x6hw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=qTIL3ASq+rlTtqjbtPifnajYOc1gsNvoX0v54/+GgME=;
 b=FY7bQ8w+HiYj3USY46INj/LE9qjL7o9Ul1kYltRu95wYf8/LRAZatfb+wESo2knyKo
 Er0IG/WuM00KxFKivTxaA7/yHgZyLrZJnoId0QJCgPALdl9tKQcrxBaeB2h1Gy371o1b
 TOJF+4W9UKQ72tMF6O8+gfm+kjLwh9nM/ZVvhgxOmXaBml6eWP8KDR+bF1oXgiIf4aBz
 GQze8p377jppdBFY36kK9tD8ScDnix+hi5fCS0AD86248cu9B8zV3Ap1gD11vUETJoh+
 ehnQ3zRZPtAthhEvXE9IDZPslW1rk22l9qjwAdGpet9QCRWXDZ/HoTe95Aee4xR8mumW
 dLDQ==
X-Gm-Message-State: AOAM531ilJlVGZg1nUA1Cq9wTkDpqkLeE4WZzR0bDdDYp3MIGeUkn3NE
 SzACuKsugDapLKr2X0gkX1Wouft0LD6d8HIberMK4KjkMT8=
X-Google-Smtp-Source: ABdhPJzXQvRQlty9K+3gcRL1HtEgLXGCStbaieTja+guNOrvDNxo+RaHFXRVzBgS46mrCuiju3LcVYTWI2IzPZMpx74=
X-Received: by 2002:a05:6602:2e95:: with SMTP id
 m21mr18299240iow.165.1595744005347; 
 Sat, 25 Jul 2020 23:13:25 -0700 (PDT)
MIME-Version: 1.0
From: =?UTF-8?Q?Marcelo_Mu=C3=B1oz?= <ma.munoz.araya@HIDDEN>
Date: Sun, 26 Jul 2020 02:13:09 -0400
Message-ID: <CA+VWJeJs0bsJvOfXrft1Ct+tO5CXvusi6Q-_pGZJFXL2pBH8Bw@HIDDEN>
Subject: 28.0.50; json-pretty-print cant't handle json having "t" as a key
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/alternative; boundary="00000000000097656505ab521a81"
Received-SPF: pass client-ip=2607:f8b0:4864:20::d36;
 envelope-from=ma.munoz.araya@HIDDEN; helo=mail-io1-xd36.google.com
X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache.
 That's all we know.
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sun, 26 Jul 2020 04:15:04 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--00000000000097656505ab521a81
Content-Type: text/plain; charset="UTF-8"

Try to apply json-pretty-print to follow json:

{"t": 1, "key":2}

fail with the message:  json-pretty-print: Bad JSON object key: t

Some research point me the problem is in the function json-encode-key,
its  implementation is:

(defun json-encode-key (object)
  "Return a JSON representation of OBJECT.
If the resulting JSON object isn't a valid JSON object key,
this signals `json-key-format'."
  (let ((encoded (json-encode object)))
    (unless (stringp (json-read-from-string encoded))
      (signal 'json-key-format (list object)))
    encoded))


The follow change seems to  solve the problem, but I haven't had time
understand it in depth:

(defun json-encode-key (object)
   "Return s string representation of a key"
   (json-encode-string (symbol-name object)))

--00000000000097656505ab521a81
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Try to apply json-pretty-print to follow json:<br><br>{&qu=
ot;t&quot;: 1, &quot;key&quot;:2}<br><br>fail with the message:=C2=A0 json-=
pretty-print: Bad JSON object key: t<br><br>Some research point me the prob=
lem is in the function json-encode-key,<br>its =C2=A0implementation is:<br>=
<br>(defun json-encode-key (object)<br>=C2=A0 &quot;Return a JSON represent=
ation of OBJECT.<br>If the resulting JSON object isn&#39;t a valid JSON obj=
ect key,<br>this signals `json-key-format&#39;.&quot;<br>=C2=A0 (let ((enco=
ded (json-encode object)))<br>=C2=A0 =C2=A0 (unless (stringp (json-read-fro=
m-string encoded))<br>=C2=A0 =C2=A0 =C2=A0 (signal &#39;json-key-format (li=
st object)))<br>=C2=A0 =C2=A0 encoded))<br><br><br>The follow change seems =
to =C2=A0solve the problem, but I haven&#39;t had time<br>understand it in =
depth:<br><br>(defun json-encode-key (object)<br>=C2=A0 =C2=A0&quot;Return =
s string representation of a key&quot;<br><div>=C2=A0 =C2=A0(json-encode-st=
ring (symbol-name object)))</div><div><br></div><div><br></div></div>

--00000000000097656505ab521a81--




Acknowledgement sent to Marcelo Muñoz <ma.munoz.araya@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#42545; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 26 Jul 2020 10:45:02 UTC

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