unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: emacs-devel@gnu.org
Subject: Native vs Elisp JSON key serialisation
Date: Tue, 28 Jul 2020 21:16:45 +0300	[thread overview]
Message-ID: <87365bbj3m.fsf@tcd.ie> (raw)

While looking at bug#42545, I noticed some inconsistencies in object key
serialisation between json-encode and json-serialize.

When serialising hash tables:
- json-encode translates the keys 'foo, :foo, and "foo" to "foo"
- json-serialize translates "foo" to "foo"
  (and rejects symbols as keys)

I don't have a problem with this; it makes sense to me that json.c is
stricter, and json.el is older so has more backward compatibility to
maintain.  In other words, the two implementations are sufficiently
consistent IMO.

When serialising alists:
- json-encode translates 'foo, :foo, and "foo" to "foo"
- json-serialize translates 'foo to "foo", and :foo to ":foo"
  (and rejects strings as keys)

Here the two implementations are inconsistent.  Should the older
json-encode also translate :foo to ":foo", or should the newer and more
prominently (in the Elisp manual) documented json-serialize translate
:foo to "foo"?

When serialising plists:
- json-encode translates :foo to "foo" (and interprets 'foo and "foo" as
  starting an array rather than associative object)
- json-serialize translates 'foo and :foo to "foo"
  (and rejects strings as keys)

Here the two implementations are again inconsistent.  Should json-encode
also accept plists with non-keyword symbols as keys, or should
json-serialize accept only keywords as keys?

In both cases, I'm inclined to change json-encode to be more consistent
with json-serialize as the more authoritative of the two.  Either way, I
think the two implementations should be as consistent and thus
interchangeable as possible.  WDYT?

-- 
Basil



             reply	other threads:[~2020-07-28 18:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28 18:16 Basil L. Contovounesios [this message]
2020-12-05 19:34 ` Native vs Elisp JSON key serialisation 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=87365bbj3m.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=emacs-devel@gnu.org \
    /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).