Hacker News new | ask | show | jobs
by a13n 3263 days ago
I love the trailing commas for function calls. Wish we could get trailing commas for all of JSON too!
5 comments

It's called JSON5 and it also has comments. The standard JSON will never "change"
For that you'd need to wait until all major parser libraries support it, aaand that all deployments get updated. That means that little change is an at least 10 year long project.
What I want are leading commas. Much tidier and one small thing you wouldn't have to edit/think about when adding and removing list items.
Better yet: automatic comma insertion! (I'm only half joking.)
Unless you need to add something to the beginning.
I prefer comma first notation.

    const hello = {
    , 'one'
    , 'two'
    , 'three
    }
would be easier to visually parse than:

    const hello = {
      'one',
      'two', 
      'three',
    }
Since the commas actually work as a guide.
Why? I just don't find myself doing too much JSON manual editing. A few config files and such. Occasional editing of a server response or call for testing.

I'm basing this on the assumption that the desire for trailing commas is making editing easier and reducing noise in diffs.

Just curious if there are niches where people are spending a lot of time manually editing JSON or if the use case is something else entirely.

I love them in code, despite initial resistance.

The use case for me is JSON blobs (mostly configuration files like package.json) that are checked into version control. Same motivations - reducing line-oriented diff noise.
I suspect that they borrowed this idea from Golang's "composite literal" spec. which is really nice feature https://dave.cheney.net/2014/10/04/that-trailing-comm
Trailing commas have been allowed in C composite literals since the dawn of time.