from Hacker News

Hjson, the Human JSON

by 56k on 4/14/16, 4:06 PM with 213 comments

  • by simonw on 4/14/16, 4:30 PM

    JSON plus comments and python-style multi-line strings is great.

    The thing where you can leave quotes off strings makes me nervous, especially the example where the value is HTML with its own embedded double quotes for attribute values.

    Not requiring quotes on strings like that looks like an obvious vector for injection attacks. I guess Hjson isn't designed to be generated automatically, but I'd prefer a format that is easy to generate safely.

    What I really want is JSON plus comments plus multi-line strings plus relaxed rules on trailing commas... While maintaining as simple and unambiguous a parsing model as possible.

  • by joeld42 on 4/14/16, 5:41 PM

    - Someone saves data as text with a simple format

    - It works great, lots of people start using it

    - People start adding features to fix annoying things with the format, add support for binary data, comments, schemas, add more metadata etc..

    - Many versions proliferate, people start writing converters and verifiers

    - A standards committee is formed and write an 800 page spec and 80kloc reference implementation

    - Eighteen different libraries wrap or reimplement the reference implementation

    - Someone gets fed up with this nonsense and converts their app to save their data in a new simple text format.

    - The circle of life continues.

    I love this idea and wish json had comments, too, but if you start hitting the point where JSON is not expressive or fluid enough, that's a hint that it's probably not the right thing for what you're doing. This variant puts a lot of work into human-friendly json, but if you're doing a lot of hand-editing of a file, it should probably not be JSON.

  • by bryanlarsen on 4/14/16, 4:30 PM

    This spec repeats one of the problems with using YAML as a configuration spec. To quote: "if your key includes a JSON control character like {}[],: or space, use quotes if your string starts with { or [, use quotes"

    JSON and YAML are interchange formats, not configuration formats. Rather than than hacking up an interchange format, it's probably better to use something designed for configuration formats, like TOML.

  • by JamilD on 4/14/16, 4:54 PM

    Rigidity and consistency are not always bad things. They can help prevent bugs, security vulnerabilities, and they drastically reduce complexity of implementation.

    JSON might often be too rigid, but I think it's important to note that "easier" (in that you don't need to learn the syntax) isn't always better.

  • by nikolay on 4/14/16, 4:40 PM

    JSON5 [0] is better as unlike Hjson, it doesn't include non-ECMASCript syntax.

    [0]: http://json5.org/

  • by ninjakeyboard on 4/14/16, 4:48 PM

    I feel like HOCON fills the space pretty well, and has implementations in most languages now. https://github.com/typesafehub/config

    But I'm a scala developer so I might be biased.

  • by creshal on 4/14/16, 4:14 PM

    What's the difference to / advantage over YAML? When I want a loose syntax "JSON with comments", I can just use that instead.
  • by al2o3cr on 4/14/16, 4:33 PM

    "Both HOCON and YAML make the mistake of implementing too many features (like anchors, sustitutions or concatenation)"

    YMMV, but if you're aiming for a format that's edited / maintained by humans things like YAML's anchors and substitution are exactly the features I'd want...

  • by brandonbloom on 4/14/16, 4:33 PM

    Just the other day I commented complaining about JSON config files without comments, but now here I am complaining about _three_ ways to write a comment. OK, I can see two ways: block and line comments. But why two ways to write line comments? Why start off a new grammar with that added complexity?
  • by jaybuff on 4/14/16, 9:02 PM

    Ah, yes, the trailing comma in a list, which I like to refer to as the "Silicon Valley Comma"

    [ "a", "b", "c", ] // the silicon valley comma

  • by o_____________o on 4/14/16, 4:35 PM

  • by rhapsodic on 4/14/16, 7:36 PM

    Looks like a solution in search of problem, to me. JSON is designed to be machine-readable, and to the extent that I actually need to human-read JSON, which is not that much, I don't find it all that difficult.
  • by xaduha on 4/14/16, 5:02 PM

    Standards are better when they are followed. Chicken and egg problem, these alternatives are DOA because they are not going to be popular.

    The only reason JSON is popular is because of Javascript. And the only reason Javascript is popular is because of the browsers and their history.

  • by wwwtyro on 4/14/16, 6:47 PM

    I've used with great results in my procedural planet generator[1]. It's very forgiving, so made writing a "UI" with lots of complicated controls very easy for me.

    [1] http://wwwtyro.github.io/planet-3d/

  • by partycoder on 4/14/16, 10:58 PM

    JSON parsers are not really slow. JSON is simple enough that allows multiple implementations for parsers and easy adoption. But HJSON additions have some serialization cost overhead.

    Because of this eventually you will need to convert your HJSON to JSON prior to deploying, and that would make things slower. You will be dealing with 2 formats instead of one.

    Then, do you really believe that adding all this syntactic "features" (overhead) will make it less error prone? It will make it more error prone because it has more things to consider!

  • by zbjornson on 4/14/16, 4:56 PM

    Oy, someone loves yaml...

    I'm quite happy using a preprocessor like [0], which keeps the great simplicity of JSON and just allows comments.

    [0] https://www.npmjs.com/package/strip-json-comments

  • by DominoTree on 4/14/16, 9:59 PM

    "Helps reduce errors" - you're really trading errors for other errors - your behavior is now more ambiguous with more edge cases, but look, you don't have to place quotes around strings! (except when you still do)
  • by mtalantikite on 4/14/16, 6:08 PM

    Can someone explain why people want to use a data-interchange format like JSON for configuration files, rather than using a configuration file format like TOML? I've never understood why people want to use JSON for config files.
  • by ebbv on 4/14/16, 4:49 PM

    This abandons a lot of principles of JSON that are there to avoid ambiguous situations. The small benefits don't seem to outweigh the snake pit you're jumping into.
  • by kennell on 4/14/16, 4:09 PM

    It has always bothered me that the JSON standard does not allow for comments. Especially when you want to annotate some sample response/request.
  • by tacone on 4/14/16, 9:17 PM

    To be honest: relaxed formats usually bring a lot of glitches to keep in mind. It's probably easier to use stricter specifications.

    Take YAML, it looks pretty natural at first sight, but has a virtually infinite list of gotchas.

  • by fibo on 4/14/16, 4:50 PM

    It already exists YAML. Also cson it is worth to look at.
  • by jordache on 4/14/16, 4:37 PM

    the json spec is pretty easy to follow, even for a human coder. this is overkill imo
  • by drewm1980 on 4/15/16, 5:57 AM

    Shouldn't we keep our format specs simple and strict, and relegate aesthetic, and typo-correction stuff to the editor?

    i.e. something with aspects of clang-format (which tries hard not to change the meaning of your code even if it's broken), and the aggressive autocorrection necessary to make typing on a touchscreen work?

    I suppose there are converters from this to json, though, so maybe this is just a better specified way of converting keypresses from monkeys into something with well defined structure...

  • by overcast on 4/14/16, 5:29 PM

    Honestly, I thought JSON was already very human readable/writable.
  • by ant6n on 4/14/16, 9:05 PM

    "Trailing commas are ignored." This is the most important :p
  • by RangerScience on 4/14/16, 10:24 PM

    Hi! I like what you've made. I have been working on something similar, although the Github is massively out of date and was never complete to begin with: https://github.com/narfanator/YAMLite (Also, I'm renaming it nowish on the up-to-date version).

    This parser handles YAML, JSON and XML. Interestingly, many of the features HJSON has, this has, by virtue of it being easier to implement during the parsing stage.

    The part I'd draw your attention to - and the part that I think warrants the most discussion - is the resulting data structure. I mostly can't tell what the structure is of the HJSON C# object - it looks like it does most of what I wanted to change about the existing C# JSON parsers, but maybe not all?

  • by kbenson on 4/14/16, 9:08 PM

    This feels like a project that had a core idea that was good and justifiable (we'll take some of the common JSON mistakes such as extra commas and most asked for features sub as comments) and then felt the need to keep throwing in features to justify its existence, and now it's lost sight of its original goal.

    This can't even be parsed natively by major JavaScript implementations, so is it really JSON at all? Actually, I think that's the root of my complaints, that it's associating itself with JSON while clearly diverging from what was important originally in JSON. At this point it's just some incompatible format leveraging the JSON name. I think most my criticisms would be ameliorated if it was just some other JSON-similar format with a different name.

  • by aeturnum on 4/14/16, 5:02 PM

    This looks pretty great.

    We've been looking for a replacement configuration format over our ancient ini files and had rejected JSON for TOML because TOML allows comments (and man, can comments be useful in configuration files). This looks like a nice medium-long term alternative.

  • by Gedrovits on 4/14/16, 5:56 PM

    Congratulations, you've created something YAML-like, non-safe data structure.
  • by sickbeard on 4/14/16, 6:20 PM

    I don't understand. doesn't commenting ruin the whole point of a human readable format? If you have to add comments, it means you need to communicate something that can be done in more concise way.
  • by erez on 4/16/16, 5:52 AM

    Human-readable json would've been a great idea, if it wasn't for the fact that json was NOT MEANT TO BE HUMAN READABLE.

    It is meant to be generated by a machine and not created by hand, neither it should be readable by humans, only parse-able by a computer.

    Treating your data interchange/serialization/configuration/markup formats as languages that should be human readable/writable is a cardinal sin of any person or company that engages in such practices.

  • by jbergstroem on 4/15/16, 6:13 AM

    Just wanted to bring libucl into the game in case you are exploring json-like syntax: https://github.com/vstakhov/libucl#improvements-to-the-json-...

    In my eyes pretty much the perfect configuration library and syntax. Nginx-alike, number suffixes (1min, 2gb, ..), macros, variables, includes with priority, etc. Boom! Problem solved.

  • by Zardoz84 on 4/15/16, 5:45 AM

    And i should remember SDLang that now have a few years and reference implementations on Java, C# and Dlang . I don't see why we need reinvent the wheel again and again...

    https://github.com/Abscissa/SDLang-D/wiki/Language-Guide

  • by paulddraper on 4/15/16, 6:47 PM

    > Significant whitespace is a common source of mistakes that we shouldn't have to deal with.

    ...except you just made it significant.

    This is JSON.

        {"a":1,"b":2,"c":3}
    
    This is Hjson after applying the mods:

        {a:1b:2c:3}
    
    ....oh, it turns out Hjson actually does have significant whitespace.
  • by roosterjm2k2 on 4/15/16, 1:08 PM

    Where is this drive to create dumb languages coming from? I dont mean dumb in the opinionated way, i mean, dumb in the way of "its hard to write proper code that follows rules, quoting and commas are hard" ... ... ... if quotes, commas and escaping is hard for you, you dont need to be an engineer....
  • by herpityderp on 4/15/16, 3:35 AM

    This looks cool, but their characterization of YAML is disingenuous

        YAML expresses structure through whitespace. Significant
        whitespace is a common source of mistakes that we
        shouldn't have to deal with.
    
    since every code editor ever used will take care of this for you.
  • by skybrian on 4/14/16, 4:28 PM

    Nice idea. A nit: making trailing whitespace significant (rather than stripping it) seems like a bug.
  • by blueadept111 on 4/14/16, 7:21 PM

    The Jaunt JSON parser (Java) was my solution to this problem. It can handle arbitrarily dirty data, including missing quotes or using semicolons instead of quotes, missing quotes, etc.

    http://jaunt-api.com

  • by Ericson2314 on 4/15/16, 4:36 AM

    Grammars people! If you don't provide it / promote it, I assume your "nice simple thing" is neither obvious nor thought-through. Sorry.

    Help me with my list of trendy things that took or are taking way to long to get a grammar: docopt, semver...

  • by dukoid on 4/14/16, 8:30 PM

  • by Murk on 4/15/16, 10:34 AM

    Comments, readability plus typabiliy where one of the main reasons I recently chose YAML for a configuration file. It seems YAML is a bit unloved these days, perhaps because it is more difficult to parse fully.

    YAML references also proved useful in my use case.

  • by joelthelion on 4/14/16, 5:52 PM

    This is overkill, but someone PLEASE add comments to the next iteration of the json spec.
  • by stock_toaster on 4/15/16, 12:16 AM

    There is also libucl[1] which is kind of json like. FreeBSD is apparently starting to use of it for a few things.

    [1]: https://github.com/vstakhov/libucl

  • by anthay on 4/15/16, 12:51 PM

    Off topic, but related: I made a simple data-serialisation file format based on S-expressions, which may be of interest to some: http://loonfile.info/
  • by rymohr on 4/14/16, 5:56 PM

    HONEY was my take at the same problem. Still brainstorming on this one and not used in production yet.

    https://github.com/honey/honey

  • by emodendroket on 4/14/16, 5:39 PM

    I'm not using a nonstandard JSON extension unless it implements a standard freaking date format. I also don't think bare strings are necessarily a great idea since they lose implicit type information.
  • by draegtun on 4/15/16, 9:06 AM

    Here's a previous HN discussion on Hjson - https://news.ycombinator.com/item?id=8432678
  • by dasmith91 on 4/15/16, 12:41 AM

    So it's YAML with all the cruft of JSON thrown back in?
  • by teen on 4/14/16, 6:25 PM

    It's almost as if you're reinventing protobufs. XD
  • by amelius on 4/14/16, 4:59 PM

    Is "undefined" part of json? Imho it should be.
  • by curryhowardiso on 4/15/16, 12:56 AM

    Soon: Situation: there are 15 competing standards.[1]

    [1]: https://xkcd.com/927/

  • by asb on 4/14/16, 6:19 PM

    Also in this space, Jsonnet is well worth a look http://jsonnet.org/
  • by pekk on 4/15/16, 5:31 AM

    YAML's problem is not "significant whitespace" which really isn't a major cause of mistakes.
  • by joejev on 4/15/16, 5:08 AM

    so in this language these all do the same thing:

    abc "abc" abc, "abc",

    How does increasing the scope simplify things? Defining correct as "crashing less often" is a really bad idea, data formats _should_ be strict.

  • by educar on 4/14/16, 9:10 PM

    Possible bug: duplicate keys are not flagged as errors (in the demo atleast)
  • by slantyyz on 4/14/16, 4:35 PM

    This looks a lot like like CSON but with better comment support.
  • by liotier on 4/15/16, 8:06 AM

    > Let's make quotes for strings optional as well.

    This will end in tears.

  • by cammil on 4/14/16, 8:38 PM

    "less mistakes" -> "fewer mistakes"
  • by msane on 4/14/16, 10:03 PM

    Seems like it would be slower to deserialize.
  • by pas256 on 4/15/16, 3:35 PM

    JSON for humans is called yaml.
  • by b34r on 4/15/16, 1:02 PM

    I'd rather just use YAML.
  • by dorfsmay on 4/14/16, 4:53 PM

    No include :-(
  • by OJFord on 4/14/16, 8:54 PM

        > , less mistakes, 
    
    Does someone have a rather subtle sense of humour, or is that a genuine mistake?! (fewer*)
  • by throwaway2093 on 4/14/16, 7:04 PM

    Worst name ever. I'm not even joking... Perhaps it would be less offensive if the last three letters didn't spell the word "SON."

    This seems pedantic, I agree, but thus is the world we live in...

    Might I suggest "Human Readable JSON."