GNU bug report logs -
#42545
json-encode-key can't handle boolean values
Previous Next
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 #8 received at 42545 <at> debbugs.gnu.org (full text, mbox):
retitle 42545 json-encode-key can't handle boolean values
found 42545 24.5
quit
Marcelo Muñoz <ma.munoz.araya <at> gmail.com> 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,
--
Basil
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.