From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Skip Montanaro Newsgroups: gmane.emacs.help Subject: Hack for JSON sequences with trailing commas? Date: Tue, 31 Jul 2018 11:58:52 -0500 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1533056040 4272 195.159.176.226 (31 Jul 2018 16:54:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 31 Jul 2018 16:54:00 +0000 (UTC) To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 31 18:53:56 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 1fkXuF-0000vX-3e for geh-help-gnu-emacs@m.gmane.org; Tue, 31 Jul 2018 18:53:55 +0200 Original-Received: from localhost ([::1]:59878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkXwK-0004TJ-98 for geh-help-gnu-emacs@m.gmane.org; Tue, 31 Jul 2018 12:56:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkXvb-0004Pb-37 for help-gnu-emacs@gnu.org; Tue, 31 Jul 2018 12:55:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkXva-0004FE-A4 for help-gnu-emacs@gnu.org; Tue, 31 Jul 2018 12:55:19 -0400 Original-Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:36584) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fkXva-0004Ex-3P for help-gnu-emacs@gnu.org; Tue, 31 Jul 2018 12:55:18 -0400 Original-Received: by mail-pf1-x431.google.com with SMTP id b11-v6so1219500pfo.3 for ; Tue, 31 Jul 2018 09:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=zCulg2rRsy1OYjms/CdL5HfDQ1J5n11pC5wJSSWiyVk=; b=U/skZCayMVBkv37PLLSNL1SmN1mvXKWDF4BaOWymF4I83TE8nYjGEg5er+EcEsKY0b 6SxXKfzT/OnATqJ4JUo94U7JHjOzFX9i1OF/sWMGQzt0teNRaphOWk0A6PIWO7eTGMXV Akz4sAu98hLOI2yS5OJZhVcsuWQjGrti3/oxoNl2+JJJusSB/7kpniyqCNMwB1Fotq4H 9YVZxlXDdMancNAHfBKgFrFXmVJeI7T566XHEl3LdrnJrSmm+R0VaKyslvU5ht6hz1w/ if+8SyD7MNDC0uZ48ypjpUg9Jz7SyquxRPA9WthL6HPisttY4djwRTWd7Cwt32yth3D4 9AGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zCulg2rRsy1OYjms/CdL5HfDQ1J5n11pC5wJSSWiyVk=; b=VZKBqufx8cIP3qeRgjiMfYrP0zPfG3tm4jUzq8uYwAFH8TaMBTxhZw7AaoCJOwYggj tXqKHwDMpHLYefTcsTLr+vI2JdAY8dt195CEYk6n7hsM2CqwVLI9bcoAk3J3O1li7J5f 3yKNI0etGOSwUHwobAf1KUZ5WMSH9XGfVddBWg2C0VpAeLKujRcejpz/kXO3r5riqsg8 dPzc08ZdnPmiN0eUckMymD7xp1SZz7CVTgJ/0v1NyYr1y3dmMfSgFREZky30dh0N4z+U 0cCcXo5fFORdJcDm373wz5nZo4+5EELWmpl+5uELhZh1/UenyJ3RYpt8qxLoAI1ZEJrv 3GQA== X-Gm-Message-State: AOUpUlH4tEWOiz6ef6RlDKqwOoTNKN3VQK6LESc9F8oj63LXCu8K2ehe ZgKIqg3rIWd1l+PiAD+CMnP9+Z6aoefktQx+iY3zD2pAKZNN X-Google-Smtp-Source: AAOMgpdS03W4ZV4oP8O1mojvc/Bf7QCWfR36T5QkgG1S6x5rCgxGXPIrV0Q5AGg1OLsT7avEsCXcwR8qMkiV1htJ4wk= X-Received: by 2002:a65:520d:: with SMTP id o13-v6mr20972557pgp.282.1533056116411; Tue, 31 Jul 2018 09:55:16 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::431 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:117615 Archived-At: 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. I'm using JSON as a config file format for some code (not as an interchange format, so I could care less what Chrome or IE think about it), so I'm actually writing it by hand. Emacs tells me "*.json" files are JavaScript, so it's quite happy with trailing commas.I installed json-mode, but it's also happy with trailing commas. Is there some clever hack to coax Emacs into stripping those trailing commas I love so much? Maybe a JSON write-file hook to strip them and a read-file-hook to add them back? For the moment, for sequences which extend across multiple lines, I've sort of adopted preceding the second through n-th elements with commas instead of appending commas to the first through n-1st elements. Thanks, Skip, missing his commas in Illinois...