From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yoichi Nakayama Newsgroups: gmane.emacs.bugs Subject: bug#24252: 25.1; json.el doesn't distinguish null and empty object Date: Sat, 20 Aug 2016 15:12:33 +0900 Message-ID: References: <0e859022-309d-576d-62ea-acaddb10a0c2@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1471673601 6017 195.159.176.226 (20 Aug 2016 06:13:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 20 Aug 2016 06:13:21 +0000 (UTC) Cc: 24252@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 20 08:13:17 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bazWu-0001K6-FR for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Aug 2016 08:13:16 +0200 Original-Received: from localhost ([::1]:59987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bazWq-0003Ed-20 for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Aug 2016 02:13:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bazWj-00039e-05 for bug-gnu-emacs@gnu.org; Sat, 20 Aug 2016 02:13:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bazWf-0006x1-Oq for bug-gnu-emacs@gnu.org; Sat, 20 Aug 2016 02:13:04 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36912) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bazWf-0006ww-L1 for bug-gnu-emacs@gnu.org; Sat, 20 Aug 2016 02:13:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bazWf-00009n-Ha for bug-gnu-emacs@gnu.org; Sat, 20 Aug 2016 02:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yoichi Nakayama Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Aug 2016 06:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24252 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24252-submit@debbugs.gnu.org id=B24252.1471673560577 (code B ref 24252); Sat, 20 Aug 2016 06:13:01 +0000 Original-Received: (at 24252) by debbugs.gnu.org; 20 Aug 2016 06:12:40 +0000 Original-Received: from localhost ([127.0.0.1]:34624 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bazWK-00009F-E2 for submit@debbugs.gnu.org; Sat, 20 Aug 2016 02:12:40 -0400 Original-Received: from mail-io0-f177.google.com ([209.85.223.177]:33932) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bazWJ-000092-PT for 24252@debbugs.gnu.org; Sat, 20 Aug 2016 02:12:40 -0400 Original-Received: by mail-io0-f177.google.com with SMTP id q83so67560688iod.1 for <24252@debbugs.gnu.org>; Fri, 19 Aug 2016 23:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=c4ouqfb8mrtWfRK0uOESjBXWVmMbavR5lHX4GqYL6VM=; b=iY+Z4461TDA0Ahijc+9g7xi28ZMfGGebBb1qinQ/oq3QRrTa1z3XON8TXf6BUzINKY jgyroVHsBxNi1NF+T8i7P5z9bdtJ/OFslsIqChab4p/iTNIu3FAev6WRzNdr49r9AlLK CwIOPnk+uJN2spcvqQDmLx9JlEXTqQ9G5xNSig9otyWNsMX7Z7foaP7bSd8rrEaLq1WH fSfkNkh9StKUHKLNsOvnh7FOLm/ZCrzC858rjuIX3D6nJRCVBHZ9sDCXBlwQmsrFdFSl YFYLggZbXf6679EozUyQjEcA/FGB3PW4AdPUByV9wWF6IAAsJaen7TIBvVUEXWuNcyXN Lh0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=c4ouqfb8mrtWfRK0uOESjBXWVmMbavR5lHX4GqYL6VM=; b=d/Le6ZvL1HDSdjusYiAYgPRgCPaEyHnBqjG/P5RGSQoFn18EroqIWq2Ti8u/km7EhQ C9pgDE4IGuiLD+1160TMTCITLoW5R3N8ANi5XcX0sSArsGpNhdB/8pIMiu9Y0q0AzpHk HtE2FlYlKzdqqe7MP2rsyJE5LnPQpIIbPoCjgK4wIZtppJBwamp3mLgArrC68d1oVBt6 fOqhgOWAEgCi4Dzoaa1utVzMRmznpgx43MfZiTn/jLrRxIbUI7q02+x9K+5qIsus9vGJ xmugz81YUdq8jtQdFW7CHMHP3RxSK5sf62uSo2rPSK8AuR1SB0gu4+PSutWqn9IrlRTy 97XA== X-Gm-Message-State: AEkoouuV7H2X6jOSDJYUkyUC4bSjSU6QnhmwmfAM6HPyrYKW+AotyLm9lvM05HR+fwg7lSwB58o9gCfh/98FTg== X-Received: by 10.107.57.215 with SMTP id g206mr14605742ioa.194.1471673554205; Fri, 19 Aug 2016 23:12:34 -0700 (PDT) Original-Received: by 10.107.3.18 with HTTP; Fri, 19 Aug 2016 23:12:33 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:122402 Archived-At: > 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 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