From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: "Marcelo Muñoz" <ma.munoz.araya@gmail.com>
Cc: 42545@debbugs.gnu.org
Subject: bug#42545: 28.0.50; json-pretty-print cant't handle json having "t" as a key
Date: Sun, 26 Jul 2020 13:38:59 +0300 [thread overview]
Message-ID: <87d04imugs.fsf@tcd.ie> (raw)
In-Reply-To: <CA+VWJeJs0bsJvOfXrft1Ct+tO5CXvusi6Q-_pGZJFXL2pBH8Bw@mail.gmail.com> ("Marcelo Muñoz"'s message of "Sun, 26 Jul 2020 02:13:09 -0400")
retitle 42545 json-encode-key can't handle boolean values
found 42545 24.5
quit
Marcelo Muñoz <ma.munoz.araya@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
next prev parent reply other threads:[~2020-07-26 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-26 6:13 bug#42545: 28.0.50; json-pretty-print cant't handle json having "t" as a key Marcelo Muñoz
2020-07-26 10:38 ` Basil L. Contovounesios [this message]
2021-02-11 14:20 ` Basil L. Contovounesios
2021-02-21 13:01 ` Basil L. Contovounesios
2021-02-23 1:23 ` Dmitry Gutov
2021-02-23 1:41 ` Basil L. Contovounesios
2021-02-23 12:10 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d04imugs.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=42545@debbugs.gnu.org \
--cc=ma.munoz.araya@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).