# JSON5 vs Hjson: Syntax and Pitfalls Compared | JSON5.dev


Source: https://json5.dev/compare/hjson/

---

# JSON5 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.

![Two config sheets on a desk, one in Hjson and one in JSON5, with a magnifier over a value that swallowed a comma](https://json5.dev/img/hero/compare-hjson.png)

**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](#origins) [Side by Side](#side-by-side) [Feature Table](#features) [Quoteless Rules](#rules) [Ambiguity Tests](#ambiguity) [Numbers](#numbers) [Writing Files](#writing) [Libraries](#libraries) [Editors](#editors) [On the Record](#on-record) [Choosing](#choosing) [Questions](#faq)

![History icon](https://json5.dev/images/icons/history.png)

## Origins and Design Goals

Hjson stands for Human JSON. Its [history page](https://hjson.github.io/history.html) 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](https://spec.json5.org/), dated March 2018, defines a [superset](https://json5.dev/glossary/#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](https://json5.dev/design-rationale/) and [history](https://json5.dev/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](https://hjson.github.io/rfc.html) dated May 23, 2016, which proposes the [media type](https://json5.dev/glossary/#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](https://json5.dev/standards/) explains where it stands.

![Compare icon](https://json5.dev/images/icons/compare.png)

## 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.

![Table icon](https://json5.dev/images/icons/table.png)

## Feature Comparison

Feature

JSON5

Hjson

Every valid JSON document accepted

![Yes](https://json5.dev/images/icons/yes.png)

![Yes](https://json5.dev/images/icons/yes.png)

`//` and `/* */` comments

![Yes](https://json5.dev/images/icons/yes.png)

![Yes](https://json5.dev/images/icons/yes.png)

`#` comments

![No](https://json5.dev/images/icons/no.png)

![Yes](https://json5.dev/images/icons/yes.png)

Trailing commas

![Yes](https://json5.dev/images/icons/yes.png)

![Yes](https://json5.dev/images/icons/yes.png)

Newline instead of a comma

![No](https://json5.dev/images/icons/no.png)

![Yes](https://json5.dev/images/icons/yes.png)

Unquoted keys

ECMAScript identifier names only

Anything without whitespace or `{}[],:`

Unquoted string values

![No](https://json5.dev/images/icons/no.png)

![Yes](https://json5.dev/images/icons/yes.png)

Single-quoted strings

![Yes](https://json5.dev/images/icons/yes.png)

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

![No](https://json5.dev/images/icons/no.png)

Yes, but the syntax page advises keeping braces for portability

Hexadecimal, leading `+`, `.5`

![Yes](https://json5.dev/images/icons/yes.png)

Read as strings by default; the optional `+hex` extension in the JavaScript library reads `0x` numbers

`Infinity` and `NaN` numbers

![Yes](https://json5.dev/images/icons/yes.png)

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](https://json5.dev/glossary/#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.

![Quote icon](https://json5.dev/images/icons/quote.png)

## How Quoteless Strings Work

The [Hjson syntax page](https://hjson.github.io/syntax.html) 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`, `false` or `null` when it can, so `7 # minutes` is the number 7 followed by a comment.
-   When that other reading fails, the whole line is text: `5 times` is 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](https://json5.dev/spec/syntax/).

### 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.

![Warning icon](https://json5.dev/images/icons/warning.png)

## 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 true``

The host passes because `"localhost,"` is a perfectly good string. A schema with patterns or enumerations is needed to reject it. The [schema validation tutorial](https://json5.dev/tutorials/schema-validation/) applies to either format.

![Number sign icon](https://json5.dev/images/icons/hashtag.png)

## Numbers That Become Strings

Because any unrecognized [token](https://json5.dev/glossary/#punctuator) 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](https://json5.dev/glossary/#leading-decimal-point) 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](https://json5.dev/spec/data-types/) lists every accepted number form.

### Optional number extensions in hjson-js

The JavaScript library ships opt-in "domain specific formats", which its [README](https://github.com/hjson/hjson-js) 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' }`

![Convert icon](https://json5.dev/images/icons/convert.png)

## 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](https://json5.dev/glossary/#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](https://json5.dev/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.

![Library icon](https://json5.dev/images/icons/book.png)

## 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 logo](https://json5.dev/images/tech/javascript.png)JavaScript

`hjson` (npm, MIT)

3.2.2, November 2020; repository last pushed February 2024

![Python logo](https://json5.dev/images/tech/python.png)Python

`hjson` (PyPI)

3.1.0, August 2022; repository pushed November 2025

![Go logo](https://json5.dev/images/tech/go.png)Go

`hjson-go/v4`

4.7.1, September 2026

![C++ logo](https://json5.dev/images/tech/cpp.svg)C++

`hjson-cpp`

2.6, April 2025; repository pushed November 2026

![Rust logo](https://json5.dev/images/tech/rust.png)Rust

`serde-hjson`; `deser-hjson`

1.1.0, September 2024; 2.2.6, June 2026

![Java logo](https://json5.dev/images/tech/java.png)Java

`org.hjson:hjson`

3.1.0; Maven metadata updated October 2023

![.NET logo](https://json5.dev/images/tech/dotnet.png).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](https://github.com/Joy-less/HjsonSharp) is archived

![PHP logo](https://json5.dev/images/tech/php.svg)PHP

`laktak/hjson`

2.3.1, May 2025

![Ruby logo](https://json5.dev/images/tech/ruby.png)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](https://json5.dev/python/), [Go](https://json5.dev/go/), [Rust](https://json5.dev/rust/), [Java](https://json5.dev/java/) and [C#](https://json5.dev/csharp/).

![Editor icon](https://json5.dev/images/icons/editor.png)

## Editor Support

The [Hjson users page](https://hjson.github.io/users.html) 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](https://json5.dev/tools/vscode/), [JetBrains IDEs](https://json5.dev/tools/jetbrains/), [Sublime Text](https://json5.dev/tools/sublime/), [Vim](https://json5.dev/tools/vim/) and [Emacs](https://json5.dev/tools/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.

![Comment icon](https://json5.dev/images/icons/comment.png)

## What Each Side Has Said

The main recorded exchange is [json5 issue #190](https://github.com/json5/json5/issues/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](https://github.com/json5/json5/issues/190#issuecomment-459637665): "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](https://github.com/json5/json5/issues/190#issuecomment-544627483): "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](https://github.com/json5/json5/issues/190#issuecomment-463082177): "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](https://github.com/json5/json5/issues/190#issuecomment-502389318) 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](https://github.com/json5/json5/issues/190#issuecomment-502418972) 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.

![Checklist icon](https://json5.dev/images/icons/checklist.png)

## 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](https://json5.dev/compare/jwcc/) or [JSONC](https://json5.dev/compare/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.

![Question icon](https://json5.dev/images/icons/question.png)

## 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.

## Related Pages

[

![Compare icon](https://json5.dev/images/icons/compare.png)

### JSON5 vs JWCC

The minimal alternative: commas and comments only.

](https://json5.dev/compare/jwcc/)[

![YAML logo](https://json5.dev/images/tech/yaml.svg)

### JSON5 vs YAML

Another format with unquoted scalars.

](https://json5.dev/compare/yaml/)[

![Branch icon](https://json5.dev/images/icons/branch.png)

### The JSON Format Family

Where every relative fits.

](https://json5.dev/family/)

## Sources

(24)

1.  [Hjson home page](https://hjson.github.io/)
2.  [Hjson syntax](https://hjson.github.io/syntax.html)
3.  [Hjson FAQ](https://hjson.github.io/faq.html)
4.  [Hjson history](https://hjson.github.io/history.html)
5.  [Hjson tools for users and editor support](https://hjson.github.io/users.html)
6.  [The Human JSON (Hjson) Configuration Format, Internet-Draft, 2016](https://hjson.github.io/rfc.html)
7.  [hjson/hjson-js README and parser source](https://github.com/hjson/hjson-js)
8.  [hjson/hjson-go](https://github.com/hjson/hjson-go)
9.  [hjson on npm](https://www.npmjs.com/package/hjson)
10.  [hjson on PyPI](https://pypi.org/project/hjson/)
11.  [serde-hjson on crates.io](https://crates.io/crates/serde-hjson)
12.  [deser-hjson on crates.io](https://crates.io/crates/deser-hjson)
13.  [org.hjson:hjson on Maven Central](https://central.sonatype.com/artifact/org.hjson/hjson)
14.  [Hjson on NuGet](https://www.nuget.org/packages/Hjson/)
15.  [HjsonSharp on NuGet](https://www.nuget.org/packages/HjsonSharp/)
16.  [Joy-less/HjsonSharp repository](https://github.com/Joy-less/HjsonSharp)
17.  [laktak/hjson on Packagist](https://packagist.org/packages/laktak/hjson)
18.  [hjson on RubyGems](https://rubygems.org/gems/hjson)
19.  [hjson/hjson-cpp](https://github.com/hjson/hjson-cpp)
20.  [Hjson extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=laktak.hjson)
21.  [GitHub Linguist language list](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml)
22.  [The JSON5 Data Interchange Format, 1.0.0](https://spec.json5.org/)
23.  [json5 on npm](https://www.npmjs.com/package/json5)
24.  [json5/json5 issue #190: Should we consolidate the human-readable JSON efforts?](https://github.com/json5/json5/issues/190)

Last reviewed: November 29, 2026.
