TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Hjson, the Human JSON

257 pointsby 56kabout 9 years ago

65 comments

simonwabout 9 years ago
JSON plus comments and python-style multi-line strings is great.<p>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.<p>Not requiring quotes on strings like that looks like an obvious vector for injection attacks. I guess Hjson isn&#x27;t designed to be generated automatically, but I&#x27;d prefer a format that is easy to generate safely.<p>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.
评论 #11498465 未加载
评论 #11498277 未加载
评论 #11498140 未加载
评论 #11498178 未加载
评论 #11500244 未加载
评论 #11502754 未加载
评论 #11498228 未加载
评论 #11500763 未加载
评论 #11499127 未加载
评论 #11502118 未加载
评论 #11502098 未加载
joeld42about 9 years ago
- Someone saves data as text with a simple format<p>- It works great, lots of people start using it<p>- People start adding features to fix annoying things with the format, add support for binary data, comments, schemas, add more metadata etc..<p>- Many versions proliferate, people start writing converters and verifiers<p>- A standards committee is formed and write an 800 page spec and 80kloc reference implementation<p>- Eighteen different libraries wrap or reimplement the reference implementation<p>- Someone gets fed up with this nonsense and converts their app to save their data in a new simple text format.<p>- The circle of life continues.<p>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&#x27;s a hint that it&#x27;s probably not the right thing for what you&#x27;re doing. This variant puts a lot of work into human-friendly json, but if you&#x27;re doing a lot of hand-editing of a file, it should probably not be JSON.
评论 #11499910 未加载
评论 #11499659 未加载
bryanlarsenabout 9 years ago
This spec repeats one of the problems with using YAML as a configuration spec. To quote: &quot;if your key includes a JSON control character like {}[],: or space, use quotes if your string starts with { or [, use quotes&quot;<p>JSON and YAML are interchange formats, not configuration formats. Rather than than hacking up an interchange format, it&#x27;s probably better to use something designed for configuration formats, like TOML.
评论 #11499542 未加载
评论 #11501172 未加载
评论 #11502485 未加载
JamilDabout 9 years ago
Rigidity and consistency are not always bad things. They can help prevent bugs, security vulnerabilities, and they drastically reduce complexity of implementation.<p>JSON might often be too rigid, but I think it&#x27;s important to note that &quot;easier&quot; (in that you don&#x27;t need to learn the syntax) isn&#x27;t always better.
评论 #11499170 未加载
评论 #11498427 未加载
评论 #11499336 未加载
nikolayabout 9 years ago
JSON5 [0] is better as unlike Hjson, it doesn&#x27;t include non-ECMASCript syntax.<p>[0]: <a href="http:&#x2F;&#x2F;json5.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;json5.org&#x2F;</a>
评论 #11498842 未加载
评论 #11498296 未加载
ninjakeyboardabout 9 years ago
I feel like HOCON fills the space pretty well, and has implementations in most languages now. <a href="https:&#x2F;&#x2F;github.com&#x2F;typesafehub&#x2F;config" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;typesafehub&#x2F;config</a><p>But I&#x27;m a scala developer so I might be biased.
评论 #11499285 未加载
评论 #11498642 未加载
creshalabout 9 years ago
What&#x27;s the difference to &#x2F; advantage over YAML? When I want a loose syntax &quot;JSON with comments&quot;, I can just use that instead.
评论 #11497979 未加载
评论 #11497993 未加载
al2o3crabout 9 years ago
&quot;Both HOCON and YAML make the mistake of implementing too many features (like anchors, sustitutions or concatenation)&quot;<p>YMMV, but if you&#x27;re aiming for a format that&#x27;s edited &#x2F; maintained by humans things like YAML&#x27;s anchors and substitution are exactly the features I&#x27;d <i>want</i>...
brandonbloomabout 9 years ago
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?
评论 #11499035 未加载
评论 #11499297 未加载
评论 #11498165 未加载
jaybuffabout 9 years ago
Ah, yes, the trailing comma in a list, which I like to refer to as the &quot;Silicon Valley Comma&quot;<p>[ &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, ] &#x2F;&#x2F; the silicon valley comma
评论 #11501223 未加载
评论 #11501560 未加载
评论 #11502651 未加载
o_____________oabout 9 years ago
CSON?<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;bevry&#x2F;cson" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bevry&#x2F;cson</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;groupon&#x2F;cson-parser" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;groupon&#x2F;cson-parser</a>
rhapsodicabout 9 years ago
Looks like a solution in search of problem, to me. JSON is designed to be machine-readable, and to the extent that I actually <i>need</i> to human-read JSON, which is not that much, I don&#x27;t find it all that difficult.
xaduhaabout 9 years ago
Standards are better when they are followed. Chicken and egg problem, these alternatives are DOA because they are not going to be popular.<p>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.
wwwtyroabout 9 years ago
I&#x27;ve used with great results in my procedural planet generator[1]. It&#x27;s very forgiving, so made writing a &quot;UI&quot; with lots of complicated controls very easy for me.<p>[1] <a href="http:&#x2F;&#x2F;wwwtyro.github.io&#x2F;planet-3d&#x2F;" rel="nofollow">http:&#x2F;&#x2F;wwwtyro.github.io&#x2F;planet-3d&#x2F;</a>
评论 #11499396 未加载
partycoderabout 9 years ago
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.<p>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.<p>Then, do you really believe that adding all this syntactic &quot;features&quot; (overhead) will make it less error prone? It will make it more error prone because it has more things to consider!
评论 #11501242 未加载
zbjornsonabout 9 years ago
Oy, someone loves yaml...<p>I&#x27;m quite happy using a preprocessor like [0], which keeps the great simplicity of JSON and just allows comments.<p>[0] <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;strip-json-comments" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;strip-json-comments</a>
评论 #11498769 未加载
DominoTreeabout 9 years ago
&quot;Helps reduce errors&quot; - you&#x27;re really trading errors for other errors - your behavior is now more ambiguous with more edge cases, but look, you don&#x27;t have to place quotes around strings! (except when you still do)
mtalantikiteabout 9 years ago
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&#x27;ve never understood why people want to use JSON for config files.
评论 #11501203 未加载
评论 #11500455 未加载
ebbvabout 9 years ago
This abandons a lot of principles of JSON that are there to avoid ambiguous situations. The small benefits don&#x27;t seem to outweigh the snake pit you&#x27;re jumping into.
kennellabout 9 years ago
It has always bothered me that the JSON standard does not allow for comments. Especially when you want to annotate some sample response&#x2F;request.
评论 #11499360 未加载
评论 #11498056 未加载
评论 #11497999 未加载
评论 #11497948 未加载
taconeabout 9 years ago
To be honest: relaxed formats usually bring a lot of glitches to keep in mind. It&#x27;s probably easier to use stricter specifications.<p>Take YAML, it looks pretty natural at first sight, but has a virtually infinite list of gotchas.
评论 #11500628 未加载
fiboabout 9 years ago
It already exists YAML. Also cson it is worth to look at.
评论 #11498945 未加载
jordacheabout 9 years ago
the json spec is pretty easy to follow, even for a human coder. this is overkill imo
评论 #11500392 未加载
drewm1980about 9 years ago
Shouldn&#x27;t we keep our format specs simple and strict, and relegate aesthetic, and typo-correction stuff to the editor?<p>i.e. something with aspects of clang-format (which tries hard not to change the meaning of your code even if it&#x27;s broken), and the aggressive autocorrection necessary to make typing on a touchscreen work?<p>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...
overcastabout 9 years ago
Honestly, I thought JSON was already very human readable&#x2F;writable.
评论 #11499189 未加载
ant6nabout 9 years ago
&quot;Trailing commas are ignored.&quot; This is the most important :p
RangerScienceabout 9 years ago
Hi! I like what you&#x27;ve made. I have been working on something similar, although the Github is <i>massively</i> out of date and was never complete to begin with: <a href="https:&#x2F;&#x2F;github.com&#x2F;narfanator&#x2F;YAMLite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;narfanator&#x2F;YAMLite</a> (Also, I&#x27;m renaming it nowish on the up-to-date version).<p>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.<p>The part I&#x27;d draw your attention to - and the part that I think warrants the most discussion - is the resulting data structure. I mostly can&#x27;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?
kbensonabout 9 years ago
This feels like a project that had a core idea that was good and justifiable (we&#x27;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&#x27;s lost sight of its original goal.<p>This can&#x27;t even be parsed natively by major JavaScript implementations, so is it really JSON at all? Actually, I think that&#x27;s the root of my complaints, that it&#x27;s associating itself with JSON while clearly diverging from what was important originally in JSON. At this point it&#x27;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.
aeturnumabout 9 years ago
This looks pretty great.<p>We&#x27;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.
Gedrovitsabout 9 years ago
Congratulations, you&#x27;ve created something YAML-like, non-safe data structure.
sickbeardabout 9 years ago
I don&#x27;t understand. doesn&#x27;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.
评论 #11499431 未加载
erezabout 9 years ago
Human-readable json would&#x27;ve been a great idea, if it wasn&#x27;t for the fact that json was NOT MEANT TO BE HUMAN READABLE.<p>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.<p>Treating your data interchange&#x2F;serialization&#x2F;configuration&#x2F;markup formats as languages that should be human readable&#x2F;writable is a cardinal sin of any person or company that engages in such practices.
jbergstroemabout 9 years ago
Just wanted to bring libucl into the game in case you are exploring json-like syntax: <a href="https:&#x2F;&#x2F;github.com&#x2F;vstakhov&#x2F;libucl#improvements-to-the-json-notation" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vstakhov&#x2F;libucl#improvements-to-the-json-...</a><p>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.
Zardoz84about 9 years ago
And i should remember SDLang that now have a few years and reference implementations on Java, C# and Dlang . I don&#x27;t see why we need reinvent the wheel again and again...<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Abscissa&#x2F;SDLang-D&#x2F;wiki&#x2F;Language-Guide" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Abscissa&#x2F;SDLang-D&#x2F;wiki&#x2F;Language-Guide</a>
paulddraperabout 9 years ago
&gt; Significant whitespace is a common source of mistakes that we shouldn&#x27;t have to deal with.<p>...except you just made it significant.<p>This is JSON.<p><pre><code> {&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3} </code></pre> This is Hjson after applying the mods:<p><pre><code> {a:1b:2c:3} </code></pre> ....oh, it turns out Hjson actually <i>does</i> have significant whitespace.
roosterjm2k2about 9 years ago
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 &quot;its hard to write proper code that follows rules, quoting and commas are hard&quot; ... ... ... if quotes, commas and escaping is hard for you, you dont need to be an engineer....
herpityderpabout 9 years ago
This looks cool, but their characterization of YAML is disingenuous<p><pre><code> YAML expresses structure through whitespace. Significant whitespace is a common source of mistakes that we shouldn&#x27;t have to deal with. </code></pre> since every code editor ever used will take care of this for you.
skybrianabout 9 years ago
Nice idea. A nit: making trailing whitespace significant (rather than stripping it) seems like a bug.
blueadept111about 9 years ago
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.<p><a href="http:&#x2F;&#x2F;jaunt-api.com" rel="nofollow">http:&#x2F;&#x2F;jaunt-api.com</a>
Ericson2314about 9 years ago
Grammars people! If you don&#x27;t provide it &#x2F; promote it, I assume your &quot;nice simple thing&quot; is neither obvious nor thought-through. Sorry.<p>Help me with my list of trendy things that took or are taking way to long to get a grammar: docopt, semver...
dukoidabout 9 years ago
There is also HUTN already: <a href="https:&#x2F;&#x2F;epsilonblog.wordpress.com&#x2F;2008&#x2F;09&#x2F;15&#x2F;new-in-hutn-071&#x2F;" rel="nofollow">https:&#x2F;&#x2F;epsilonblog.wordpress.com&#x2F;2008&#x2F;09&#x2F;15&#x2F;new-in-hutn-071...</a>
Murkabout 9 years ago
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.<p>YAML references also proved useful in my use case.
joelthelionabout 9 years ago
This is overkill, but someone PLEASE add comments to the next iteration of the json spec.
stock_toasterabout 9 years ago
There is also libucl[1] which is kind of json like. FreeBSD is apparently starting to use of it for a few things.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;vstakhov&#x2F;libucl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vstakhov&#x2F;libucl</a>
评论 #11501945 未加载
anthayabout 9 years ago
Off topic, but related: I made a simple data-serialisation file format based on S-expressions, which may be of interest to some: <a href="http:&#x2F;&#x2F;loonfile.info&#x2F;" rel="nofollow">http:&#x2F;&#x2F;loonfile.info&#x2F;</a>
rymohrabout 9 years ago
HONEY was my take at the same problem. Still brainstorming on this one and not used in production yet.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;honey&#x2F;honey" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;honey&#x2F;honey</a>
emodendroketabout 9 years ago
I&#x27;m not using a nonstandard JSON extension unless it implements a standard freaking date format. I also don&#x27;t think bare strings are necessarily a great idea since they lose implicit type information.
draegtunabout 9 years ago
Here&#x27;s a previous HN discussion on Hjson - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8432678" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8432678</a>
dasmith91about 9 years ago
So it&#x27;s YAML with all the cruft of JSON thrown back in?
评论 #11515056 未加载
teenabout 9 years ago
It&#x27;s almost as if you&#x27;re reinventing protobufs. XD
ameliusabout 9 years ago
Is &quot;undefined&quot; part of json? Imho it should be.
评论 #11498457 未加载
curryhowardisoabout 9 years ago
Soon: Situation: there are 15 competing standards.[1]<p>[1]: <a href="https:&#x2F;&#x2F;xkcd.com&#x2F;927&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;927&#x2F;</a>
asbabout 9 years ago
Also in this space, Jsonnet is well worth a look <a href="http:&#x2F;&#x2F;jsonnet.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;jsonnet.org&#x2F;</a>
评论 #11500555 未加载
pekkabout 9 years ago
YAML&#x27;s problem is not &quot;significant whitespace&quot; which really isn&#x27;t a major cause of mistakes.
joejevabout 9 years ago
so in this language these all do the same thing:<p>abc &quot;abc&quot; abc, &quot;abc&quot;,<p>How does increasing the scope simplify things? Defining correct as &quot;crashing less often&quot; is a really bad idea, data formats _should_ be strict.
educarabout 9 years ago
Possible bug: duplicate keys are not flagged as errors (in the demo atleast)
slantyyzabout 9 years ago
This looks a lot like like CSON but with better comment support.
liotierabout 9 years ago
&gt; Let&#x27;s make quotes for strings optional as well.<p>This will end in tears.
cammilabout 9 years ago
&quot;less mistakes&quot; -&gt; &quot;fewer mistakes&quot;
msaneabout 9 years ago
Seems like it would be slower to deserialize.
pas256about 9 years ago
JSON for humans is called yaml.
b34rabout 9 years ago
I&#x27;d rather just use YAML.
评论 #11515049 未加载
dorfsmayabout 9 years ago
No include :-(
评论 #11500231 未加载
OJFordabout 9 years ago
<p><pre><code> &gt; , less mistakes, </code></pre> Does someone have a rather subtle sense of humour, or is that a genuine mistake?! (fewer*)
throwaway2093about 9 years ago
Worst name ever. I&#x27;m not even joking... Perhaps it would be less offensive if the last three letters didn&#x27;t spell the word &quot;SON.&quot;<p>This seems pedantic, I agree, but thus is the world we live in...<p>Might I suggest &quot;Human Readable JSON.&quot;
评论 #11499916 未加载
评论 #11500637 未加载
评论 #11500619 未加载