From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Hack for JSON sequences with trailing commas? Date: Wed, 01 Aug 2018 02:53:23 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 X-Trace: blaine.gmane.org 1533106402 8323 195.159.176.226 (1 Aug 2018 06:53:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Aug 2018 06:53:22 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 01 08:53:18 2018 Return-path: Envelope-to: geh-help-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 1fkl0X-000244-2p for geh-help-gnu-emacs@m.gmane.org; Wed, 01 Aug 2018 08:53:17 +0200 Original-Received: from localhost ([::1]:33762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkl2d-0003kf-L4 for geh-help-gnu-emacs@m.gmane.org; Wed, 01 Aug 2018 02:55:27 -0400 X-Received: by 2002:a1c:8492:: with SMTP id g140-v6mr764562wmd.2.1533106403724; Tue, 31 Jul 2018 23:53:23 -0700 (PDT) Original-Path: usenet.stanford.edu!s3-v6no319930wmf.0!news-out.google.com!i6-v6ni7481wmf.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!2.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 37 Original-Injection-Info: barmar.motzarella.org; posting-host="cfe85b79bfbbf65bcce0435a634faa99"; logging-data="19810"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LZPS8OWtu46XEBqeKXMWq" Cancel-Lock: sha1:L3jrHny30B44yFFW+/Bre8Orwh8= Original-Xref: usenet.stanford.edu gnu.emacs.help:223492 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117617 Archived-At: In article , Skip Montanaro wrote: > I've been using programming languages where sequences can contain > trailing commas since my earliest days with C back in the early 80s. > Of course, Python (the language in which I write most things these > days) supports that. As does JavaScript, though for some crazy reason, > not if that JavaScript is just JSON. This is a valid JSON input > string: > > "[1,2,3]" > > but attempts to decode this string using Python's json.loads() > function provoke a JSONDecodeError: > > "[1,2,3,]" > > *sigh* > > I suppose if I was to dig enough I'd find a reason JSON's author > thought that was a good idea. JSON is a very limited subset of Javascript notation for literals. Many things that are allowed in Javascript source code are not allowed in JSON. The reason is presumably to simplify the design of JSON parsers -- they don't have to deal with all possible input formats. For instance, Javascript allows both single and double quotes to be used as string delimiters, but JSON only allows double quotes. Javascript allows object keys to be written without quoting them if they're valid JS names, JSON requires all keys to be quoted. And JS allows trailing commas, JSON doesn't. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***