[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Accept plists when serializing and parsing JSON

From: Philipp Stephani
Subject: Re: [PATCH] Accept plists when serializing and parsing JSON
Date: Sat, 2 Jun 2018 10:24:20 +0200

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

New patch after my sig

Thanks, some more detailed comments:


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

"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, @address@hidden@}}, not @code{null},
address@hidden, or an empty array, all of which are different JSON

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]