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

Previous Next

Package: emacs;

Reported by: Marcelo Muñoz <ma.munoz.araya <at> gmail.com>

Date: Sun, 26 Jul 2020 08:16:01 UTC

Severity: normal

Tags: fixed, patch

Merged with 45032, 46174, 46811

Found in versions 24.5, 26.3, 27.1, 28.0.50

Fixed in version 28.1

Done: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Marcelo Muñoz <ma.munoz.araya <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; json-pretty-print cant't handle json having "t" as a key
Date: Sun, 26 Jul 2020 02:13:09 -0400
[Message part 1 (text/plain, inline)]
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)))
[Message part 2 (text/html, inline)]

This bug report was last modified 4 years and 80 days ago.

Previous Next


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