all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
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: Sun, 21 Aug 2016 10:30:25 +0900	[thread overview]
Message-ID: <CAF5D8-uEJJQztBguBhtvvKk4JWXLSYozYMs63Ze063oUzyM5gA@mail.gmail.com> (raw)
In-Reply-To: <CAF5D8-s_Mmb=vH_EZEJpda-6GvEFoRKshdFuZ3kUg9Qi=Z6iow@mail.gmail.com>

The second patch dosn't work with some cases. Applying json-pretty-print to
{":json-null": 1}
cause error "Bad JSON object key: :json-null".


On Sat, Aug 20, 2016 at 3:12 PM, Yoichi Nakayama
<yoichi.nakayama@gmail.com> wrote:
>> Maybe the fix could be in json-pretty-print.
>
> I agree that json-pretty-print should be responsible to the issue.
> But I think
>
> (let ((json-null 'NULL)) (json-encode (json-read-from-string "{}")))
>
> is also a bug.
> How about the following patch?
>
> From 24a11fc81ea283c7f999bbcf87ea0f2c01c1c24e Mon Sep 17 00:00:00 2001
> From: Yoichi Nakayama <yoichi.nakayama@gmail.com>
> Date: Sat, 20 Aug 2016 15:00:28 +0900
> Subject: [PATCH] Distinguish empty json object and null
>
> * lisp/json.el (json-encode-list, json-encode): Handle empty object
> correctly when json-null is not nil.
> (json-pretty-print): Bind json-null to distinguish empty object and null.
> ---
>  lisp/json.el | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/json.el b/lisp/json.el
> index fdac8d9..a439f77 100644
> --- a/lisp/json.el
> +++ b/lisp/json.el
> @@ -588,7 +588,7 @@ Please see the documentation of `json-object-type'
> and `json-key-type'."
>    "Return a JSON representation of LIST.
>  Tries to DWIM: simple lists become JSON arrays, while alists and plists
>  become JSON objects."
> -  (cond ((null list)         "null")
> +  (cond ((eq json-null list) "null")
>          ((json-alist-p list) (json-encode-alist list))
>          ((json-plist-p list) (json-encode-plist list))
>          ((listp list)        (json-encode-array list))
> @@ -700,12 +700,12 @@ Advances point just past JSON object."
>          ((stringp object)      (json-encode-string object))
>          ((keywordp object)     (json-encode-string
>                                  (substring (symbol-name object) 1)))
> -        ((symbolp object)      (json-encode-string
> -                                (symbol-name object)))
>          ((numberp object)      (json-encode-number object))
>          ((arrayp object)       (json-encode-array object))
>          ((hash-table-p object) (json-encode-hash-table object))
>          ((listp object)        (json-encode-list object))
> +        ((symbolp object)      (json-encode-string
> +                                (symbol-name object)))
>          (t                     (signal 'json-error (list object)))))
>
>  ;; Pretty printing
> @@ -722,6 +722,8 @@ Advances point just past JSON object."
>      (let ((json-encoding-pretty-print t)
>            ;; Ensure that ordering is maintained
>            (json-object-type 'alist)
> +          ;; Distinguish empty object and null
> +          (json-null :json-null)
>            (txt (delete-and-extract-region begin end)))
>        (insert (json-encode (json-read-from-string txt))))))
>
> --
> 2.8.1



-- 
Yoichi NAKAYAMA





  reply	other threads:[~2016-08-21  1:30 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
2016-08-20  0:52     ` Dmitry Gutov
2016-08-20  6:12       ` Yoichi Nakayama
2016-08-21  1:30         ` Yoichi Nakayama [this message]
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-uEJJQztBguBhtvvKk4JWXLSYozYMs63Ze063oUzyM5gA@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.