all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Skip Montanaro <skip.montanaro@gmail.com>
To: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Hack for JSON sequences with trailing commas?
Date: Tue, 31 Jul 2018 11:58:52 -0500	[thread overview]
Message-ID: <CANc-5UwunGrN-0QGBR4sG4s7aYkzsBPyK3nctRKpWokjhgiPww@mail.gmail.com> (raw)

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...



             reply	other threads:[~2018-07-31 16:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 16:58 Skip Montanaro [this message]
     [not found] <mailman.4482.1533056121.1292.help-gnu-emacs@gnu.org>
2018-08-01  6:53 ` Hack for JSON sequences with trailing commas? Barry Margolin
2018-08-01  7:22   ` Yuri Khan
2018-08-01  9:58     ` Skip Montanaro
2018-08-01 14:40   ` Drew Adams
     [not found]   ` <mailman.4559.1533134429.1292.help-gnu-emacs@gnu.org>
2018-08-02 22:42     ` Barry Margolin
     [not found]       ` <mailman.4627.1533257510.1292.help-gnu-emacs@gnu.org>
2018-08-04 23:12         ` Barry Margolin
     [not found]     ` <<barmar-81F7D5.18423702082018@reader.eternal-september.org>
2018-08-03  0:51       ` Drew Adams

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=CANc-5UwunGrN-0QGBR4sG4s7aYkzsBPyK3nctRKpWokjhgiPww@mail.gmail.com \
    --to=skip.montanaro@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.