hjson / hjson-js

Hjson for JavaScript
https://hjson.github.io/
MIT License
416 stars 49 forks source link

How does this compare to json5? #48

Open TheKnarf opened 5 years ago

TheKnarf commented 5 years ago

How does this compare to json5? Would be nice if the readme at least mentioned whats different between the two.

vwbusguy commented 4 years ago

The things that I can see that are most obvious is that json5 requires comma delimiting (though trailing commas are OK) and quoting of strings as a value (keys do not need quoted), but json5 also supports in-line comments.

lewisl9029 commented 2 years ago

I've been researching config formats lately, and so far hjson is the front-runner for supporting comment-preserving edits in its node implementation. Haven't found anything else yet that satisfies this requirement in a node implementation. Kudos to the hjson team for prioritizing this awesome feature!

dqsully commented 2 years ago

JSON5 is a project to use ES5-like syntax for config files, and it's mainly tailored to a JavaScript implementation last I checked. Hjson is a similar format designed to be more a more human-friendly version of JSON, and has libraries across many different languages. They are indeed very similar - they are both supersets of JSON that try to improve the UX, but take slightly different and incompatible approaches.

Compared to JSON5, in Hjson commas are optional at the ends of lines, quoteless object keys are more flexible, and quoteless string values are a thing (although they are slightly different than YAML's quoteless strings). However, Hjson does not natively support hex, octal, or binary numbers, NaNs, infinities, or leading plusses like JSON5 does.

The JavaScript implementation of Hjson is the main one, and it supports node-based comment editing like @lewisl9029 mentioned in trying to satisfy the concept of a config file as human-machine interface.