all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: "João Távora" <joaotavora@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: [PATCH] Accept plists when serializing and parsing JSON
Date: Sat, 2 Jun 2018 10:24:20 +0200	[thread overview]
Message-ID: <CAArVCkQn5U=HUgPtZZ1+HbdAUuUYgZnFx8wjrdp8Hxxu6eGoGA@mail.gmail.com> (raw)
In-Reply-To: <87d0xaozl1.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2728 bytes --]

João Távora <joaotavora@gmail.com> schrieb am Sa., 2. Juni 2018 um
01:30 Uhr:

>
> New patch after my sig
>
>
Thanks, some more detailed comments:

test.texi:

When an alist or plist
+contains several elements with the same key, Emacs uses only the first
+element for serialization, in accordance with the behavior of
+@code{assq}.

"in accordance with ... assq and plist-get" (plist-get also uses the first
element)

+Note that @code{nil} is both a valid alist and a valid plist and
+represents the empty JSON object, @code{@{@}}, not @code{null},
+@code{false}, or an empty array, all of which are different JSON
+values.

This is a bit hard to parse, could you split it up into multiple sentences?

 or @code{plist} to use plists with keyword
+symbols as keys.

It's merely a somewhat common convention to use keywords (starting with :)
in plist keys. I think it's better to just use the same symbols, i.e.
neither add nor strip colons. That would also make the implementation
simpler.

You should also mention how the function distinguishes between alists and
plists.

+          /* If using plists, maybe strip the ":" from symbol-name */
+          if (is_plist &&
+              ':' == key_str[0] &&
+              key_str[1] ) key_str = &key_str[1];

As said above, I think it's better to remove this code (and maybe document
that colons aren't stripped). Especially the "maybe" part makes the
interface more complex and subtle. For example, a caller sees that (a 1 b
2) gets serialized to {"a": 1, "b": 2} and then might reasonably conclude
that (a 1 :a 2) gets serialized to {"a": 1, ":a": 2}, but that would be
wrong. It's more obvious and easier to understand to not treat colons
specially.

+Vectors will be converted to JSON arrays, and hashtables and alists to
+JSON objects.

Mention plists. (MIght be better to split this up into two sentences,
and/or switch to active voice.)

+                  char *keyword_key_str = SAFE_ALLOCA (1 + strlen(key_str)
+ 1);
+                  keyword_key_str[0]=':';

Again, no special treatment for colons please.

+see.  The returned object will be a vector, hashtable, alist, or
+plist.  Its elements will be `:null', `:false', t, numbers, strings,

Nit: you're using Oxford commas inconsistently. I'm fine either way, but
please stay consistent.

+  (should-error (json-serialize '#1=(:a 1 . #1#)) :type 'circular-list)

Add another unit test to check that circularity in values is detected (i.e.
'#1=(:a 1 :b . #1#)).

Otherwise this looks fine to me. I'm still not super convinced we need to
support plists at all for serialization, but the auto-detection looks
reliable and obvious enough.

[-- Attachment #2: Type: text/html, Size: 3795 bytes --]

  parent reply	other threads:[~2018-06-02  8:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29 14:59 [PATCH] Accept plists when serializing and parsing JSON João Távora
2018-05-29 21:20 ` Philipp Stephani
2018-05-29 22:03   ` João Távora
2018-05-30  6:37     ` Yuri Khan
2018-05-30  8:58       ` João Távora
2018-06-02  8:04         ` Philipp Stephani
2018-06-03  0:34           ` João Távora
2018-06-03  4:05             ` Stefan Monnier
2018-06-03 13:43               ` João Távora
2018-06-02  7:45       ` Philipp Stephani
2018-06-02  7:39     ` Philipp Stephani
2018-06-01  9:39 ` Eli Zaretskii
2018-06-01 23:29   ` João Távora
2018-06-02  6:55     ` Eli Zaretskii
2018-06-02  8:24     ` Philipp Stephani [this message]
2018-06-02  9:00       ` Eli Zaretskii
2018-06-02 16:46         ` Philipp Stephani
2018-06-02 19:18           ` Eli Zaretskii
2018-06-08 14:45     ` Eli Zaretskii
2018-06-02  8:30 ` Philipp Stephani

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAArVCkQn5U=HUgPtZZ1+HbdAUuUYgZnFx8wjrdp8Hxxu6eGoGA@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.