bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#24252: 25.1; json.el doesn't distinguish null and empty object


From: Dmitry Gutov
Subject: bug#24252: 25.1; json.el doesn't distinguish null and empty object
Date: Fri, 19 Aug 2016 05:06:48 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Thunderbird/47.0

Hi!

On 08/17/2016 05:54 PM, Yoichi Nakayama wrote:

When json-pretty-print applied to "{}", it is
unexpectedly converted to "null".
This is caused by internal representations of null
and empty object are the same:
  (json-read-from-string "{}") ; => nil
  (json-read-from-string "null") ; => nil

Why don't you bind json-null to whatever value you need? Then the results will be different:

ELISP> (let ((json-null 'NULL)) (json-read-from-string "null"))
NULL

+(defvar json-empty-object :json-empty-object
+  "Value to use when reading JSON `{}'.
+If this has the same value as `json-null', you might not be able to tell
+the difference between `{}' and `null'.  Consider let-binding this
+around your call to `json-read' instead of `setq'ing it.")

This doesn't look like a good default value, at least. It's not one of the types that we parse JSON objects to (alist, plist, hash-table). This will break real code.

By the way, another option to distinguish nil and {} is to bind json-object-type to `hash-table'. An empty hash table is not nil.





reply via email to

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