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 08:45:18 +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 1471650381 2307 195.159.176.226 (19 Aug 2016 23:46:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 19 Aug 2016 23:46: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 01:46: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 1batUP-0000KS-FI for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Aug 2016 01:46:17 +0200 Original-Received: from localhost ([::1]:59356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1batUM-0004et-Hp for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Aug 2016 19:46:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1batUG-0004eZ-Gu for bug-gnu-emacs@gnu.org; Fri, 19 Aug 2016 19:46:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1batUA-00030S-FY for bug-gnu-emacs@gnu.org; Fri, 19 Aug 2016 19:46:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1batUA-00030O-C2 for bug-gnu-emacs@gnu.org; Fri, 19 Aug 2016 19:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1batUA-0007pu-2S for bug-gnu-emacs@gnu.org; Fri, 19 Aug 2016 19:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yoichi Nakayama Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Aug 2016 23:46:02 +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.147165032630080 (code B ref 24252); Fri, 19 Aug 2016 23:46:02 +0000 Original-Received: (at 24252) by debbugs.gnu.org; 19 Aug 2016 23:45:26 +0000 Original-Received: from localhost ([127.0.0.1]:34571 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1batTa-0007p5-HE for submit@debbugs.gnu.org; Fri, 19 Aug 2016 19:45:26 -0400 Original-Received: from mail-it0-f52.google.com ([209.85.214.52]:37491) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1batTY-0007os-CL for 24252@debbugs.gnu.org; Fri, 19 Aug 2016 19:45:24 -0400 Original-Received: by mail-it0-f52.google.com with SMTP id f6so38242592ith.0 for <24252@debbugs.gnu.org>; Fri, 19 Aug 2016 16:45:24 -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=sw3P+WDxBjwG81KeRMOJZN81wAUdcR9QtitHBMwblEg=; b=VfBcGvvvZYwZMuvJT9cjBfv9gBrYGjBxmi9WEoiH8L4ChJlFe4EzdWMppjPQVXu4Is 7RetYcp6idOk/ZxFIk0ud3w/tKIKZWekNNDvOjnUM1QsHO2/iPgfl+/5eeusa6qm0nEA 3wHoa0V1ywK8X/1aUXyQYWuMEui52ZwdyDzh1QlLzQjBXABHZQUhP22yBnEr7wVs4mW1 NtFAI7AKxbXSDq7m2hPHiNHPN+4/OZ8X0cbZjhwPssXmYWaM7V0e4YhDwVO85rmuDmPl TXyM7OmPGnnqwD3GRcMh2Aw17XWufQ3qJDWPkhy/kNklEt7LSAqr4eyYa5AM5IZ7Op2t VjLQ== 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=sw3P+WDxBjwG81KeRMOJZN81wAUdcR9QtitHBMwblEg=; b=hcYwX2iy/auZlUTclMRX1w0Z5124L65l/av23nh7Eh10WzI0Macfi+C/y/FxGbDfMu anztSrqWw28wydBfBAUqzXg7QcfO46bJyjpZsfOXvR90vbfTN4oWem2ZXvn1rPj60y19 pnCEGnjX1xrOwGbiTA5Xm1BIbszgyC9doYu60d2IFWW2rFDsEvV/ZunUbCfH9upS2qaP v8ffQcaPiHSxGPnPcR/M56TA4Pwp06iQISdrfinhEAjdN6rgy7VKlW0QqvTIMzPh0oxR kRHOBKnp3CBARq5qOupIXIQGnapeoYXOPdVkoYY18uiBD/BU82rJQgYls48At6W17TXL onLg== X-Gm-Message-State: AEkoous3TxLpfmuJORO3RqpPhFq7Tue39i0D9m2OuoMIZsz7eYVw/+l8ObAGmOhd4loPHzl0LfPPeqsM22ZXWg== X-Received: by 10.36.33.17 with SMTP id e17mr9379151ita.41.1471650318709; Fri, 19 Aug 2016 16:45:18 -0700 (PDT) Original-Received: by 10.107.3.18 with HTTP; Fri, 19 Aug 2016 16:45:18 -0700 (PDT) In-Reply-To: <0e859022-309d-576d-62ea-acaddb10a0c2@yandex.ru> 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:122396 Archived-At: > 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 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