[HN Gopher] JSON5 - JSON for Humans
       ___________________________________________________________________
        
       JSON5 - JSON for Humans
        
       Author : rickcarlino
       Score  : 39 points
       Date   : 2024-12-08 21:29 UTC (1 hours ago)
        
 (HTM) web link (json5.org)
 (TXT) w3m dump (json5.org)
        
       | ruuda wrote:
       | If you're looking for a human-friendly json superset (comments,
       | non-quoted keys) that can also abstract away repetitive
       | configuration with variables and list comprehensions, check out
       | https://rcl-lang.org/.
        
       | qwertox wrote:
       | Comments are nice. I wonder if they can also be inserted
       | programmatically.
        
         | VTimofeenko wrote:
         | It kinda becomes a question of "does this comment annotate the
         | line it's on, the next one, or the arbitrary number of
         | succeeding lines" since the order of the objects is not
         | guaranteed by the standard and when writing comments by hand
         | it's common to say "the next section shall do X".
        
       | yashap wrote:
       | I'm a fan of JSON5. A common criticism is "we've already got YAML
       | for human readable config with comments," but IMO YAML's
       | readability sucks, it's too hard to tell what's an object and
       | what's an array at a glance (at least, with the way it's often
       | written).
       | 
       | When dealing with large YAML files, I find myself frequently
       | popping them into online "YAML to JSON" tools to actually figure
       | out WTF is going on. JSON5 is much easier to read, at least for
       | me.
        
         | stackskipton wrote:
         | Those two criticisms of YAML are at bottom of my list. Space as
         | delimiter and lack of strict typing is what screws me over on
         | daily basis as SRE.
        
           | yashap wrote:
           | Fair, YAML has a lot of usability warts, and those suck too.
           | Although personally I really do hate how tough it is to tell
           | apart arrays and objects, at least with the most common YAML
           | array/object style.
        
         | marcyb5st wrote:
         | What's your take on prototxt files? In my opinion it is the
         | most readable format since you don't need square brackets for
         | repeated fields/arrays.
         | 
         | Additionally plugins let you link your prototxt file with the
         | corresponding proto so you can spot errors right away.
        
         | BurningFrog wrote:
         | If you already have a bunch of JSON documents, you can keep
         | using them with JSON5.
         | 
         | That's a big advantage compared to converting to YAML.
        
           | knowsuchagency wrote:
           | same is true of YAML as a JSON superset
        
         | couscouspie wrote:
         | Just in case you didn't know: With
         | https://github.com/mikefarah/yq you can just immediately
         | translate YAMLs like                 yq some.yaml -o json
        
       | bawolff wrote:
       | As much as i like this (yaml goes way too far, but trailing
       | commas and comments would make json much nicer. I actually think
       | this spec goes too far with single quotes) i hate that it is
       | named json5. I think its unethical to imply you are the next
       | version of something if you don't have the blessing of the
       | original author.
        
         | j1elo wrote:
         | I would think that the name JSON5 pretends to be nothing more
         | than a pun on Michael Jackson's original band, The Jackson 5.
         | 
         | If it didn't originate from that, the name wouldn't make sense
         | to me any more.
        
           | bawolff wrote:
           | The project description describes it as json plus syntax from
           | emcascript 5.1 (commonly called ES5) [the official name of
           | javascript is emcascript]. I imagine that is where the name
           | comes from.
           | 
           | Although it doesn't really make sense since most of the stuff
           | they add predates ES5.
        
           | zeven7 wrote:
           | I assumed it was a play on HTML5 -\\_(tsu)_/-
        
           | dcre wrote:
           | Ha. There is no way that's what it means unless you read that
           | somewhere.
        
         | Dylan16807 wrote:
         | Even when the original author said it was "discovered"?
         | 
         | JSON5 is closer to "javascript object notation" than JSON
         | itself. It's partly an update and partly a removal of arbitrary
         | restrictions.
        
         | papa-whisky wrote:
         | I think the name just means that it sits in-between JSON and
         | ES5 (i.e., it's a superset of JSON and subset of ES5).
         | 
         | edit: well as this comment thread indicates, the name is pretty
         | confusing for everyone :)
        
       | eknkc wrote:
       | I feel like the comments are the only important part. I'd rather
       | not have single quoted strings or unquoted identifiers to be
       | honest. Trailing commas are nice to have though.
       | 
       | All I miss in JSON are comments and a native datetime type.
       | Everything else, I'm fine with.
        
         | BurningFrog wrote:
         | For comments, adding "_comment": "..." fields can work pretty
         | well.
        
           | viraptor wrote:
           | Not where the reader verifies the schema. And not when you
           | want to write a long multiline comment. (Unless you want
           | _comment1, _comment2, ...)
        
         | sevensor wrote:
         | Strongly disagree about datetimes; they exist at a different
         | semantic level and are entirely too easy to get wrong.
        
       | epscylonb wrote:
       | I've always been a big fan of KDL in principle, haven't used it
       | in anger. After that HCL, then YAML, with JSON and others being
       | my least favourite to use.
       | 
       | Of course the hard part is gaining enough critical mass to make a
       | significant switch. JSON had AJAX. YAML had Rails. What could
       | make JSON5 or KDL break out?
        
       | brap wrote:
       | Would it be correct to say that this is basically any valid JS
       | code that describes an object, excluding the use of references
       | and function definitions?
       | 
       | If not, what is the difference, and why was it made to be
       | different?
        
         | bawolff wrote:
         | Seems like the escapes are slightly different. No astral
         | unicode escapes (e.g. \u{123456} ). No octal escapes \123
         | 
         | No template literals (backticks)
         | 
         | No regex literals
         | 
         | No octal numbers (0123, 0o123)
         | 
         | No boolean numbers (0b1001)
         | 
         | No big ints (the "n" suffix)
        
       | sethops1 wrote:
       | May I suggest using TOML, which in my experience has been the
       | perfect blend of human readability while having good tooling.
       | 
       | https://toml.io/en/
        
         | viraptor wrote:
         | Their dictionaries and arrays split into ini-like sections are
         | not very readable though. The double [[ is just nasty and not
         | possible to apply in all situations (array in map in array).
        
       | nikeee wrote:
       | I think it allows for too much. I was glad that JSON only
       | supports double-quoted strings. It is a feature that removes
       | discussions about which quotes to use. Or even whether to use
       | quotes at all (we still need them for keys with colons or minus
       | in it, so what gives?).
       | 
       | The only thing that JSON is really missing are comments and
       | trailing commas. I use JSONC for that. It's what VSC uses for the
       | config format and it works.
        
       | hi_hi wrote:
       | Isn't JSON for humans essentially YAML? (only kinda joking)
        
         | sevensor wrote:
         | That was the idea, before it all went terribly wrong.
        
       | cute_boi wrote:
       | If browser/node etc.. starts to support json5, i am sure it won't
       | take that much time to get adopted.
        
       ___________________________________________________________________
       (page generated 2024-12-08 23:00 UTC)