From: Yoichi Nakayama <yoichi.nakayama@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 24252@debbugs.gnu.org
Subject: bug#24252: 25.1; json.el doesn't distinguish null and empty object
Date: Sat, 20 Aug 2016 08:45:18 +0900 [thread overview]
Message-ID: <CAF5D8-tPzpJ3ZjSs8iFojUCniOo=fbp0x108rfQaQN6AGZbfFw@mail.gmail.com> (raw)
In-Reply-To: <0e859022-309d-576d-62ea-acaddb10a0c2@yandex.ru>
> Why don't you bind json-null to whatever value you need?
(let ((json-null 'NULL)) (json-encode (json-read-from-string "{}")))
"\"nil\""
> 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.
It does not work because json-pretty-print overwrites json-object-type.
On Fri, Aug 19, 2016 at 11:06 AM, Dmitry Gutov <dgutov@yandex.ru> wrote:
> 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.
--
Yoichi NAKAYAMA
next prev parent reply other threads:[~2016-08-19 23:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 14:54 bug#24252: 25.1; json.el doesn't distinguish null and empty object Yoichi Nakayama
2016-08-19 2:06 ` Dmitry Gutov
2016-08-19 23:45 ` Yoichi Nakayama [this message]
2016-08-20 0:52 ` Dmitry Gutov
2016-08-20 6:12 ` Yoichi Nakayama
2016-08-21 1:30 ` Yoichi Nakayama
2016-08-21 3:42 ` Dmitry Gutov
2016-08-21 12:11 ` Yoichi Nakayama
2016-08-21 13:32 ` Yoichi Nakayama
2016-08-21 15:06 ` Yoichi Nakayama
2016-08-27 0:05 ` Dmitry Gutov
2018-05-17 14:39 ` Damien Cassou
2018-05-19 6:52 ` Damien Cassou
2018-05-28 15:21 ` Nicolas Petton
2018-06-11 13:36 ` Damien Cassou
2018-06-12 17:14 ` Eli Zaretskii
2018-06-13 7:13 ` Damien Cassou
2018-06-13 13:05 ` Nicolas Petton
2018-06-13 16:55 ` Eli Zaretskii
2018-06-14 9:04 ` Nicolas Petton
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='CAF5D8-tPzpJ3ZjSs8iFojUCniOo=fbp0x108rfQaQN6AGZbfFw@mail.gmail.com' \
--to=yoichi.nakayama@gmail.com \
--cc=24252@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
/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.