vs Hjson: Syntax and Parsing
Two ways to make JSON friendlier, with very different ideas about quotes.
JSON5 borrows syntax from ECMAScript 5 and keeps every string quoted. Hjson lets you drop the quotes, drop most commas, write # comments and indent multiline text, which reads beautifully until a value means something you did not intend.
This page compares both grammars from their own documentation, runs the same awkward inputs through the hjson and json5 npm packages, checks library releases by language, and records what each side has said about the other.
TL;DR: Pick JSON5 when mistakes should fail loudly and the file should look like JavaScript. Pick Hjson when people who do not write code edit prose-heavy settings and you validate the result against a schema. Both read ordinary JSON. Neither one reads all of the other.
Origins and Design Goals
Hjson stands for Human JSON. Its history page dates the first draft to March 19, 2014 and says it grew out of frustration with editing JSON config files. The project describes itself as a syntax extension to JSON that is explicitly not a proposal to replace it: a person reads and edits Hjson, and the machine receives JSON. Its home page also states that the project is now entirely community-supported.
JSON5 starts from a narrower rule. The 1.0.0 specification, dated March 2018, defines a superset of JSON whose additions come from ECMAScript 5.1. If a piece of syntax is not in that language, it is not in the format. That single constraint explains almost every difference below, and the design rationale and history pages cover it in detail.
| Milestone from the Hjson history page | Date |
|---|---|
| First draft | 2014-03-19 |
| Multiline strings added | 2014-05-09 |
| Media type and file extension added | 2014-12-02 |
// and /* */ comments added | 2015-01-02 |
Quoteless strings simplified: they may now start with a digit, true, false or null | 2015-01-06 |
| Optional root braces allowed | 2015-05-06 |
| Optional root braces deprecated (the syntax page now says they are supported again) | 2016-09-27 |
| Single-quoted strings added | 2017-07-13 |
On the standards side, the Hjson site hosts an Internet-Draft by C. Zangl dated May 23, 2016, which proposes the media type application/hjson and carries an expiry date of November 24, 2016. It is not an RFC. The draft also notes that Hjson, unlike JSON, is not a subset of JavaScript. JSON5 is not an RFC either; the standards page explains where it stands.
The Same Config in Both Formats
Here is one service configuration in idiomatic Hjson. Keys and most values are bare, no commas appear, and the banner uses a triple-quoted block:
# service settings
{
name: api
port: 8080
banner:
'''
Welcome.
Be kind.
'''
tags: [
web
internal
]
}And the same data written as JSON5:
{
// service settings
name: 'api',
port: 8080,
banner: 'Welcome.\nBe kind.',
tags: [
'web',
'internal',
],
}With hjson 3.2.2 and json5 2.2.3 on Node.js 24.22.1, both parse to exactly this:
{"name":"api","port":8080,"banner":"Welcome.\nBe kind.","tags":["web","internal"]}The Hjson version has fewer characters to type and nothing to escape. The JSON5 version shows, at every value, whether you are looking at a string or a number. The rest of this page is about what that visibility is worth.
Feature Comparison
| Feature | JSON5 | Hjson |
|---|---|---|
| Every valid JSON document accepted | ||
// and /* */ comments | ||
# comments | ||
| Trailing commas | ||
| Newline instead of a comma | ||
| Unquoted keys | ECMAScript identifier names only | Anything without whitespace or {}[],: |
| Unquoted string values | ||
| Single-quoted strings | Yes, though the syntax page warns that some platforms may lag | |
| Multiline strings | Backslash before the line break; the break is not part of the value | Triple single quotes; indentation is stripped, breaks are kept |
| Root object without braces | Yes, but the syntax page advises keeping braces for portability | |
Hexadecimal, leading +, .5 | Read as strings by default; the optional +hex extension in the JavaScript library reads 0x numbers | |
Infinity and NaN numbers | Strings by default; the optional +math extension reads Inf, -Inf and NaN, but not the word Infinity | |
| File extension | .json5 | .hjson |
"Superset" is therefore only true relative to JSON. A JSON5 file that uses a backslash line continuation fails in hjson 3.2.2 with Bad string, and a file with mask: 0xFF on a line of its own inside the braces loads without any error but delivers the string "0xFF". Renaming a file from one extension to the other is never a safe migration.
How Quoteless Strings Work
The Hjson syntax page gives the rules. Understanding them removes most surprises:
- A quoteless string may not start with
{ } [ ] , :, with a quote mark, or with a comment opener. - It runs to the end of the line. Commas, closing braces,
#and//after it become part of the value. - Leading and trailing whitespace is trimmed, and backslashes are literal.
- It is the fallback: the parser reads a number,
true,falseornullwhen it can, so7 # minutesis the number 7 followed by a comment. - When that other reading fails, the whole line is text:
5 timesis the string"5 times".
Multiline strings
A value that opens with three single quotes continues until the next three. The column of the opening quotes sets the indentation to strip, further indentation is preserved, the final line break is dropped, and line endings are always \n regardless of platform. JSON5 has no equivalent. Its line continuation joins lines without a break, so you write \n yourself; see the syntax reference.
Keys
Hjson accepts my-key bare. Given { my-key: 1 }, JSON5 rejects it with invalid character '-' at 1:5, because a hyphen is not legal in an ECMAScript identifier name. Quote such keys, as you would in JavaScript.
Ambiguity, Demonstrated
Quoteless strings move a class of errors from parse time to run time. Every row below is real output from hjson 3.2.2 and json5 2.2.3. \n marks a line break in the input. Hjson behaves as documented in these cases; the question is whether the documented behavior is what the author of the file meant.
| Input | Hjson.parse | JSON5.parse |
|---|---|---|
{\n host: localhost,\n} | {"host":"localhost,"} | Error: invalid character 'l' |
{\n enabled: flase\n} | {"enabled":"flase"} | Error: invalid character 'l' |
{\n a: True\n b: NULL\n c: yes\n} | {"a":"True","b":"NULL","c":"yes"} | Error: invalid character 'T' |
{\n timeout: 30 # seconds\n mode: fast # not slow\n} | {"timeout":30,"mode":"fast # not slow"} | Error: invalid character '#' |
{\n url: http://example.com/x # y\n} | {"url":"http://example.com/x # y"} | Error: invalid character 'h' |
{\n a:\n b: 2\n} | {"a":"b: 2"} | Error: invalid character 'b' |
{\n one: #FF00AA\n two: #00FF00\n} | {"one":"two: #00FF00"} | Error: invalid character '#' |
[\n a b c\n] | ["a b c"] | Error: invalid character 'a' |
[a, b, c] | Error: missing ] | Error: invalid character 'a' |
{ enabled: flase } | Error: missing } | Error: invalid character 'l' |
{ a: 1 b: 2 } | Error: missing } | Error: invalid character 'b' |
| An empty file | {} | Error: invalid end of input |
Four of these deserve a comment:
- The stray comma. Someone used to JSON ends a line with a comma. After a number or a quoted string it is a separator; after a bare word it is data.
- The typo.
"flase"is a non-empty string, so JavaScript and many other languages treat it as true. A switch someone meant to turn off is on. - The missing value. The parser skips the line break after
a:and takes the next line as the string. - The color code. Unquoted
#starts a comment. The syntax page documents this exact result as a known oversight that implementations may handle differently.
The same line can also change meaning with layout: [a, b, c] on one line is an error, while spreading three words across one line inside a multiline array yields one element. Note too that duplicate keys are accepted by both libraries, with the last value winning, so neither protects you there.
Guarding an Hjson config
If you accept Hjson, check types after parsing. This script catches the typo, and also shows what a type check cannot catch:
const Hjson = require('hjson');
const source = `{
# connection settings
port: 8080
host: localhost,
debug: flase
}`;
const config = Hjson.parse(source);
const expected = { port: 'number', host: 'string', debug: 'boolean' };
for (const [key, type] of Object.entries(expected)) {
if (typeof config[key] !== type) console.log(`${key}: expected ${type}, got ${JSON.stringify(config[key])}`);
}
console.log(config.host.endsWith(','), Boolean(config.debug));
// Output:
// debug: expected boolean, got "flase"
// true trueThe host passes because "localhost," is a perfectly good string. A schema with patterns or enumerations is needed to reject it. The schema validation tutorial applies to either format.
Numbers That Become Strings
Because any unrecognized token falls back to text, number spellings outside JSON's grammar do not raise errors in Hjson. These values were parsed one per line by hjson 3.2.2 with default options; the right column is the JSON5 reading under its specification.
| Written | Hjson result | JSON5 |
|---|---|---|
1e3 | number 1000 | number 1000 |
5. | number 5 | number 5 |
0x1F | string "0x1F" | number 31 |
.5 | string ".5" | number 0.5 |
+1 | string "+1" | number 1 |
Infinity | string "Infinity" | number Infinity |
NaN | string "NaN" | number NaN |
007 | string "007" | syntax error |
1_000 | string "1_000" | syntax error |
1.10 | number 1.1 | number 1.1 |
02134 | string "02134" | syntax error |
The last two rows matter for version strings and postal codes. In Hjson, a leading zero keeps 02134 as text, but a version written 1.10 silently turns into the number 1.1. JSON5 reads it as a number too, but its quoting rule already trains authors to write '1.10' when they mean text. The data types page lists every accepted number form.
Optional number extensions in hjson-js
The JavaScript library ships opt-in "domain specific formats", which its README marks as experimental. They change what the reader recognizes, so a file that relies on them means something else to a program that leaves them off:
const Hjson = require('hjson');
const options = { dsf: [Hjson.dsf.math(), Hjson.dsf.hex()] };
const text = '{\n a: 0x1F\n b: Inf\n c: Infinity\n}';
console.log(Hjson.parse(text, options));
console.log(Hjson.parse(text));
// { a: 31, b: Infinity, c: 'Infinity' }
// { a: '0x1F', b: 'Inf', c: 'Infinity' }Writing, Comments and Conversion
Hjson's writer is careful about the ambiguity its reader allows. Hjson.stringify in version 3.2.2 emits bare words for ordinary strings but adds quotes to the strings "true" and "5" so they survive a round trip, and writes a value containing a line break as a triple-quoted block. It writes Infinity and NaN as null by default, as JSON.stringify does. JSON5.stringify quotes every string and writes the non-finite numbers literally.
Keeping comments
This is a real Hjson advantage. The JavaScript library offers a round-trip mode that stores comments and whitespace in a non-enumerable member and writes them back. The Hjson FAQ cautions that not every implementation does this yet.
const data = Hjson.rt.parse('{\n # keep me\n a: 1\n}');
data.a = 2;
console.log(Hjson.rt.stringify(data));
// {
// # keep me
// a: 2
// }The json5 package has no comment-preserving mode: parse returns plain values. See implementations for other libraries.
Converting Hjson to JSON5
Convert through parsed values, never by renaming. JSON5.stringify(Hjson.parse(text), null, 2) does the job, drops all comments, and faithfully preserves any mistake the Hjson parser accepted. On the broken config above it produces:
{
port: 8080,
host: 'localhost,',
debug: 'flase',
}That output is also the quickest audit: once every string is quoted, the bad ones are easy to see. Review it, restore the comments by hand, then validate.
Libraries and Maintenance by Language
The Hjson site lists implementations for more languages than many people expect. The releases below were read from each package registry or repository on November 29, 2026. A quiet repository is not necessarily a broken one, since a small stable grammar needs little work, but check open issues before adopting.
| Language | Package | Latest release seen |
|---|---|---|
JavaScript | hjson (npm, MIT) | 3.2.2, November 2020; repository last pushed February 2024 |
Python | hjson (PyPI) | 3.1.0, August 2022; repository pushed November 2025 |
hjson-go/v4 | 4.7.1, September 2026 | |
hjson-cpp | 2.6, April 2025; repository pushed November 2026 | |
Rust | serde-hjson; deser-hjson | 1.1.0, September 2024; 2.2.6, June 2026 |
Java | org.hjson:hjson | 3.1.0; Maven metadata updated October 2023 |
.NET | Hjson; also HjsonSharp | Hjson 3.0.0 (July 2017), prerelease 4.0.0-rc.1 (March 2026); HjsonSharp 3.10.0, which NuGet marks as legacy in favor of JsonhCs and whose repository is archived |
laktak/hjson | 2.3.1, May 2025 | |
Ruby | hjson gem | 0.1.2, October 2017 |
| Lua and Raku | hjson-lua, JSON::Hjson | Listed by the Hjson site |
For comparison, the JavaScript reference library json5 is at 2.2.3, released December 31, 2022. For the week of November 22 to 28, 2026, the npm registry reported 303,643,299 downloads of json5 and 471,863 of hjson, a ratio of more than 600 to 1. Download counts include transitive installs by build tools, so they measure reach, not preference. For JSON5 choices elsewhere, see the guides for Python, Go, Rust, Java and C#.
Editor Support
The Hjson users page lists syntax highlighting for Ace, Atom, Emacs, IntelliJ, Notepad++, Sublime Text, TextMate-compatible editors, Vim, Visual Studio and Visual Studio Code. These are mostly separate small packages. The VS Code extension, laktak.hjson, was at version 0.3.3, last updated January 2025, with about 34,000 installs when checked, and its README describes it as adding syntax support.
GitHub's Linguist language list, which drives highlighting on GitHub, has a JSON5 entry for the .json5 extension. We found no Hjson entry in that file. For JSON5 setup, see the guides for VS Code, JetBrains IDEs, Sublime Text, Vim and Emacs.
On the command line, npm install hjson -g provides an hjson tool: hjson -j file.hjson prints formatted JSON, and the FAQ suggests this convert-then-run pattern for applications that read only JSON.
What Each Side Has Said
The main recorded exchange is json5 issue #190, "Should we consolidate the human-readable JSON efforts?", opened by a user on February 1, 2019 and closed on June 5, 2020 after 72 comments. We found no mention of JSON5 on the Hjson home, syntax, FAQ, history or users pages.
Jordan Tucker, a JSON5 project member, gave the first substantive reply: "Hjson and YAML are easy to write, but they add a lot of syntax that is not compatible with JavaScript." In October 2019 he restated the boundary: "JSON5 is obviously derived from ES5, which doesn't support optional commas, uses C style comments, and doesn't support unquoted string values or multi-line strings."
He did not rule out a merger on principle. In February 2019 he wrote: "I'm not opposed to merging JSON5 into another JSON for Humans project, but I'd prefer that it is compatible with ECMAScript syntax and doesn't add any new data types over JSON."
From the Hjson side, GitHub user dqsully, listed as a maintainer of the hjson npm package, welcomed collaboration while naming the difference: "Hjson is meant to be a cross-platform configuration language, focusing on being easy for humans to use, whereas JSON(5, 6, 7, etc.) seems to be more focused on compatibility with JavaScript." Hours later the same contributor acknowledged the cost discussed on this page: "quoteless strings can be a big compatibility issue, since almost anything that isn't another kind of value automatically becomes a quoteless string." The concern raised there was forward compatibility: adding any new keyword would change the meaning of existing files.
Others in the thread argued both ways. The Hjson contributor held up round-trip comment handling as a feature Hjson had shown people want. Other participants objected that optional commas make line breaks significant and that a second line-comment style adds nothing. The user who opened the issue closed it by observing that "we definitely are NOT consolidating anything". No merged format came out of it.
Choosing Between Them
| Your situation | Lean toward | Why |
|---|---|---|
| Developers maintain the config | JSON5 | Familiar JavaScript syntax; typos fail at load |
| Values drive security or money decisions | JSON5, plus a schema | No implicit strings |
| Non-programmers edit long text and patterns | Hjson, plus a strict schema | No escaping, indented blocks |
| Your program rewrites a commented file | Hjson in JavaScript, or a round-trip library | Built-in comment preservation |
| The tool already reads one of them | That one | A second format costs more than either syntax saves |
| Machines exchange the data | JSON | The Hjson draft and FAQ say not to use Hjson for protocols |
| You only want comments and trailing commas | JWCC or JSONC | Smallest step from JSON |
The trade is clear when stated plainly. Hjson optimizes the moment of writing: less punctuation, no escaping. JSON5 optimizes the moment something is wrong: a bare word is an error with a line and column. If you adopt Hjson, adopt validation with it, tell authors to quote anything followed by a comment or comma, and keep root braces for portability.
Common Questions
Is Hjson a superset of JSON5?
No. Both accept JSON, but with default options several JSON5 forms either fail in Hjson (backslash line continuation) or load as different values (hexadecimal, .5, +1, Infinity, NaN).
Does JSON5 allow unquoted strings at all?
Only as object keys that are valid identifier names. A bare word in value position is an error unless it is true, false, null, Infinity or NaN.
Is Hjson abandoned?
No, but activity is uneven. The Go and C++ repositories saw pushes in November 2026, while the JavaScript package has not had a release since 2020.
Can I use Hjson for an API?
The project advises against it. Its FAQ says to keep Hjson for humans and convert to JSON before sending data to a machine, and specifically rules out protocols and databases.
How do I write a # color in Hjson?
Quote it: color: "#00FF00". Unquoted, the # begins a comment.
Sources
(24)
- Hjson home page
- Hjson syntax
- Hjson FAQ
- Hjson history
- Hjson tools for users and editor support
- The Human JSON (Hjson) Configuration Format, Internet-Draft, 2016
- hjson/hjson-js README and parser source
- hjson/hjson-go
- hjson on npm
- hjson on PyPI
- serde-hjson on crates.io
- deser-hjson on crates.io
- org.hjson:hjson on Maven Central
- Hjson on NuGet
- HjsonSharp on NuGet
- Joy-less/HjsonSharp repository
- laktak/hjson on Packagist
- hjson on RubyGems
- hjson/hjson-cpp
- Hjson extension for Visual Studio Code
- GitHub Linguist language list
- The JSON5 Data Interchange Format, 1.0.0
- json5 on npm
- json5/json5 issue #190: Should we consolidate the human-readable JSON efforts?
Last reviewed: November 29, 2026.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Lua
Babel
Vite
webpack
ESLint
Prettier
VS Code
JetBrains
.NET