# JSON5 vs JWCC and HuJSON: What Differs | JSON5.dev


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

---

# JSON5 vs JWCC and HuJSON Compared

Two features added to JSON, or a whole ECMAScript 5 vocabulary.

JWCC, short for JSON With Commas and Comments, adds trailing commas and C-style comments to JSON and stops there. HuJSON is Tailscale's Go package for it. JSON5 goes further, with unquoted keys, single quotes and a wider number syntax.

This page sets out what JWCC deliberately leaves out, quotes the published argument for that restraint and answers it point by point, and walks through the standardize, format and patch operations in HuJSON using its source and test tables.

![A short JWCC toolbox with two tools, commas and comments, beside a larger JSON5 toolbox on a workbench](https://json5.dev/img/hero/compare-jwcc.png)

**TL;DR:** Choose **JWCC** when the file must map to JSON with no loss, or when a Go program must edit it and keep the comments. Choose **JSON5** when authors benefit from bare keys, single quotes, hexadecimal or non-finite numbers. Nearly every JWCC document is also valid JSON5 with the same value; the reverse is not true.

[What JWCC Is](#definition) [What It Excludes](#excluded) [Compatibility](#compatibility) [The Argument](#argument) [Converting to JSON](#downgrade) [HuJSON](#hujson) [Standardize](#standardize) [Patch](#patch) [Tooling](#tooling) [Choosing](#choosing) [Questions](#faq)

![Specification icon](https://json5.dev/images/icons/spec.png)

## What JWCC Is

Nigel Tao published ["JSON With Commas and Comments"](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html) on February 22, 2021. The post is the closest thing the format has to a definition. An update added four days later says the format is not a novel invention: people keep wanting it and re-inventing it, so it may as well have a standard name and file extension. He proposes `.jwcc` and the [media type](https://json5.dev/glossary/#media-type) `application/jwcc`.

The rules fit in a short list:

-   One optional comma may follow the final element of an array or the final member of an object.
-   `/* block */` and `// line` comments may appear anywhere JSON allows whitespace.
-   A line comment ends at a line feed byte. Carriage returns do not matter, and a comment on the last line may omit the line feed (a point revised in July 2021).
-   Everything else is JSON, so every JSON file is valid JWCC.

`{ // Listen address "addr": ":8080", /* Feature flags */ "flags": [ "a", "b", ], }`

That document is also valid JSON5: `json5` 2.2.3 parses it to `{"addr":":8080","flags":["a","b"]}`. Strict JSON parsers reject it because of the comments and [trailing commas](https://json5.dev/glossary/#trailing-comma).

The idea predates the name. The first commit in Tailscale's [hujson repository](https://github.com/tailscale/hujson) is dated September 29, 2019, and Tao's post calls it a case of parallel evolution. Today the package README describes it as an implementation of JWCC.

![Forbidden icon](https://json5.dev/images/icons/forbidden.png)

## What JWCC Leaves Out

Feature

JSON5

JWCC

Reason or behavior

Comments

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

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

One of the two additions

Trailing comma

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

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

The other; a lone `[,]` is an error in both

Unquoted keys

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

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

`invalid character 'n' at start of object name`

Single-quoted strings

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

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

Considered and dropped, per the post

Multiline strings

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

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

Considered and dropped

Leading `+`

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

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

`invalid literal: +1000`

Hexadecimal, `.5`, `5.`

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

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

Numbers follow JSON

`NaN`, `Infinity`

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

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

Keeps the JSON object model

Extra escapes such as `\v` and `\x41`

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

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

Strings follow JSON

Extra whitespace characters

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

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

Only space, tab, CR and LF

`#` comments

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

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

Not valid JavaScript

Missing commas

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

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

Not valid JavaScript

Duplicate keys prohibited

Not prohibited

Not prohibited

JWCC keeps JSON behavior on purpose

The quoted error messages come from the test table in [HuJSON](https://json5.dev/glossary/#hujson)'s `json_test.go`; the other JWCC rows follow from the definition and from `parse.go`, which validates each literal as JSON. On duplicate keys, the post argues that JWCC is a [superset](https://json5.dev/glossary/#superset) of JSON with its flaws included, and that detecting duplicates costs memory proportional to the input. For the JSON5 side of each row, see the [syntax reference](https://json5.dev/spec/syntax/).

![Layers icon](https://json5.dev/images/icons/layers.png)

## Is JWCC a Subset of JSON5?

For the documents people write by hand, yes. At the edges, not quite, because the two define the end of a [line comment](https://json5.dev/glossary/#line-comment) differently. JWCC ends it only at a line feed. JSON5, following ECMAScript, also ends it at a carriage return and at the Unicode line and [paragraph separators](https://json5.dev/glossary/#line-separator) U+2028 and U+2029.

Input, with escapes standing for the raw characters

`json5` 2.2.3 result

Under JWCC rules and the HuJSON source

`[1, // x\r2\n]`

`[1,2]`

The comment swallows `2`, leaving `[1]` with a trailing comma

`[1, // x\u20282\n]`

`[1,2]`

By the post's rule the separator is part of the comment; HuJSON instead rejects U+2028 and U+2029 inside a line comment

The first case needs a lone carriage return in the middle of a line, which ordinary editors do not produce: Windows line endings put the line feed immediately after it, and both formats then agree. The second is a deliberate guard that HuJSON [added in July 2026](https://github.com/tailscale/hujson/commit/b80ff77d), to reject input whose meaning would change between HuJSON or JWCC and JavaScript-style comment parsers. Both characters remain legal inside strings and block comments. If untrusted parties author your files and two parsers read them, treat any disagreement of this kind as a security concern and use one parser for both the check and the use.

JSON5 also accepts whitespace JWCC does not. `json5` reads a number preceded by a no-break space and followed by a vertical tab without complaint.

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

## The Published Argument, Answered

The post is often cited as a case against JSON5. It is worth reading precisely. Its opening theme is extensibility: JSON is easy to understand, so people extend it, and lenient parsers accumulate behavior that later cannot be tightened. It then argues for clarity over terseness, and its FAQ asks why not use JSON5, the komkom variant of JSONC, Hjson or HOCON instead.

### "I think unquoted strings are a mistake."

That sentence, with a pointer to the section on clarity, is the whole answer, and it covers several formats at once. The supporting examples are a typo such as `flase` being accepted as text, and `[a b c]` having no obvious meaning. JSON5 does not have the feature those examples describe. It has no unquoted string values. We ran each through `json5` 2.2.3:

Input

Result

`{ enabled: flase }`

`invalid character 'l' at 1:13`

`[a b c]`

`invalid character 'a' at 1:2`

`{ a: undefined }`

`invalid character 'u' at 1:6`

`{ null: 1, true: 2, NaN: 3 }`

`{"null":1,"true":2,"NaN":3}`

What JSON5 does allow is an unquoted object _key_ that is a legal identifier name. A key is always followed by a colon, so it cannot be confused with a value, as the last row shows. The criticism applies fully to [Hjson](https://json5.dev/compare/hjson/); for JSON5 it can only be about keys, where it becomes a preference for one spelling.

### Keeping room for new keywords

The post warns that giving bare words a string meaning rules out adding keywords later, using `undefined` and `datetime` as examples. In JSON5 an unknown bare value is still a syntax error, so that room remains open in principle. In practice the format is deliberately tied to ES5, and its published specification is version 1.0.0 from March 2018. It also claimed two words JSON lacks, `Infinity` and `NaN`.

### The object model

This is the strongest point, and it stands. Asked why not allow non-finite numbers, the post says that sharing JSON's object model makes upgrading easier because no code meets a previously impossible NaN, and adds: "Downgrading JWCC to JSON is trivial. Downgrading e.g. JSON5 to JSON is not. There is no obvious unambiguous mapping from a JSON5 NaN to JSON." That is correct. The gap is confined to non-finite numbers, so a project can close it with a rule or a check, but it has to know to do so.

### Where to stop

On single-quoted and multiline strings the post says they "were considered, but a line had to be drawn somewhere", judging commas and comments the largest pain points. JSON5 draws its line elsewhere, at what ES5 already defines. Both are bounded rules. The costs differ: JSON5 needs its own parser with a larger grammar, while a JWCC reader can strip two constructs and hand the rest to an existing JSON parser. In return, JSON5 authors get bare keys, quote choice and hexadecimal. The post closes the question evenly: "if you like e.g. JSON5 then use JSON5", noting that some people prefer JSON-like trade-offs.

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

## Converting JSON5 to JSON Safely

In JavaScript the lossy step is silent. `JSON.stringify` writes `null` for `Infinity` and `NaN`, while a hexadecimal number converts cleanly:

`const value = JSON5.parse('{limit: Infinity, ratio: NaN, mask: 0xFF}'); console.log(JSON.stringify(value)); // {"limit":null,"ratio":null,"mask":255}`

A replacer turns that silent loss into an error:

`function toStrictJSON(value) { return JSON.stringify(value, (key, v) => { if (typeof v === 'number' && !Number.isFinite(v)) { throw new RangeError('no JSON form for ' + key + ': ' + v); } return v; }); } // toStrictJSON(value) throws: RangeError: no JSON form for limit: Infinity`

HuJSON faces the same question when a Go program constructs a value. Its `hujson.Float` function represents NaN and the infinities as the JSON strings `"NaN"`, `"Infinity"` and `"-Infinity"`, and `Literal.Float` reads those strings back as numbers. It is a workable convention, and it shows the ambiguity the post describes: only the program knows whether the string was meant as a number. The [conversion guide](https://json5.dev/tools/conversion/) covers other directions.

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

## HuJSON: The Go Package

`github.com/tailscale/hujson` is published under a BSD-style license. When checked, its newest version on the Go module proxy was the pseudo-version dated November 28, 2026, the repository listed no version tags, and `go.mod` declared Go 1.26. Tailscale uses the format for its [tailnet policy file](https://tailscale.com/docs/features/tailnet-policy-file).

The design is a syntax tree rather than a decoder. `Parse` returns a `Value` that records every literal, comment and run of whitespace, so `Pack` reproduces the input byte for byte if nothing changed. There is no `Unmarshal` of its own; you standardize to JSON and use `encoding/json`:

`func load(path string, out any) error { raw, err := os.ReadFile(path) if err != nil { return err } std, err := hujson.Standardize(raw) // may overwrite raw in place if err != nil { return err } return json.Unmarshal(std, out) }`

**The input buffer is shared.** The source documents that parsed values alias the slice you pass in, and the formatter command copies its input because the transforms can modify it. Pass `bytes.Clone(raw)` if you need the original afterward.

Parse errors carry a position, for example `hujson: line 1, column 6: invalid character ',' after top-level value`. We saw no nesting-depth limit in the recursive parser, so cap the size of untrusted input before parsing. General Go options are on the [Go page](https://json5.dev/go/).

![Text format icon](https://json5.dev/images/icons/text-format.png)

## Standardize, Minimize and Format

Operation

Effect

Output is strict JSON

`Standardize`

Replaces comments and trailing commas with spaces, keeping line numbers and byte offsets

Yes

`Minimize`

Removes whitespace, comments and trailing commas

Yes

`Format`

Applies an opinionated layout and keeps comments

Only if the input already was

`IsStandard`

Reports whether comments and trailing commas are absent

Not applicable

Preserving offsets is the useful idea in `Standardize`: when `encoding/json` reports a byte position in the cleaned text, it points at the same place in the file the author wrote. These pairs come from the package's test table. Look at the gap where the trailing comma was:

`input: { "k" : "v" , } Standardize: { "k" : "v" } Minimize: {"k":"v"}`

`Format` is described as the equivalent of `go fmt`: idempotent, tab-indented, ending with one newline, with a warning that its exact output may change over time. From the formatting tests:

`input: [null/**/,null] Format: [null /**/ , null] input: {"name"/**/:"value"/**/,"name":"value"} Format: {"name" /**/ : "value" /**/ , "name": "value"}`

It also rewrites string escapes into a normal form. On any parse error, the three byte-slice functions return the original input together with the error, so check the error before using the result. The [formatting guide](https://json5.dev/tools/formatting/) covers JSON5 formatters.

![Edit icon](https://json5.dev/images/icons/edit.png)

## Patching Without Losing Comments

`Value.Patch` applies a [JSON Patch (RFC 6902)](https://www.rfc-editor.org/rfc/rfc6902) to the syntax tree, supporting `add`, `remove`, `replace`, `move`, `copy` and `test`. The patch may itself be HuJSON, and comments around an inserted value travel with it. `Value.Find` looks up a single value by [JSON Pointer (RFC 6901)](https://www.rfc-editor.org/rfc/rfc6901), returning the first match if a name is duplicated and `nil` if nothing matches.

``v, err := hujson.Parse(raw) if err != nil { return err } next := v.Clone() // a failed patch can leave a value half changed patch := []byte(`[{"op": "replace", "path": "/port", "value": 9090}]`) if err := next.Patch(patch); err != nil { return err } next.Format() return os.WriteFile(path, next.Pack(), 0o644)``

### What happens to comments

Replacing a value keeps the comments around it. Removing one also removes the comments attached to it; another case in the same tests shows that comment blocks set apart from the removed value by a blank line stay. This case is from `patch_test.go`, with three labels added:

`// document [ // Comment3 "value1", // Comment4 // Comment3 "value2", // Comment4 // Comment3 "value3" // Comment4 ] // patch: [ { "op": "remove", "path": "/1" }, ] // result [ // Comment3 "value1", // Comment4 // Comment3 "value3" // Comment4 ]`

### Edge cases worth knowing

-   **Not atomic.** If an operation fails, earlier ones remain applied to the receiver. Clone first.
-   **No automatic formatting.** Inserted members land compactly, such as `{ "foo": "bar","baz":"qux"}`; call `Format` afterward.
-   **Strict about operations.** An unknown `op` (the names are case-sensitive), a duplicated member, a missing `path`, removing the root, or moving a value into itself each return an error.
-   **Some comments are lost.** The source assumes there are no comments between a member name and its colon, between the colon and the value, or between a value and its comma, and says such comments will be lost when patching. Put comments above a member or after its comma.
-   **Limits of `test`.** The test table records open items: `9223372036854775800` currently compares equal to `9223372036854775801`, a document with duplicate names can pass, and `1e1000` fails to equal itself. Do not rely on `test` for exact large integers.

We did not find an equivalent comment-preserving patch operation in the `json5` JavaScript package, whose API returns plain values. If a program must edit a commented file, this is the clearest practical argument for JWCC in Go.

![Tools icon](https://json5.dev/images/icons/tools.png)

## Command Line and Editors

HuJSON ships `hujsonfmt`. By default it prints formatted output; `-w` rewrites files, `-l` lists files that differ, `-d` shows diffs, `-s` standardizes to JSON and `-m` minifies. Given a directory, it processes files ending in `.hujson`.

`go install github.com/tailscale/hujson/cmd/hujsonfmt@latest hujsonfmt -w policy.hujson hujsonfmt -s policy.hujson > policy.json`

Tao's post shows a second tool: `jsonptr`, from the Wuffs library, which speaks strict JSON by default and accepts JWCC with `-jwcc` or converts it with `-input-jwcc`. A 2021 update to the post also notes that RapidJSON supports comments and trailing commas.

The post also explains why it did not simply adopt the VS Code "JSON with Comments" name: the label JSONC was already used for two different formats, and those files carry the `.json` extension although they are not JSON.

![VS Code logo](https://json5.dev/images/tech/vscode.png)In VS Code, the HuJSON README suggests associating `*.hujson` with the `jsonc` language and allowing trailing commas through a schema setting:

`"files.associations": { "*.hujson": "jsonc" }, "json.schemas": [{ "fileMatch": ["*.hujson"], "schema": { "allowTrailingCommas": true } }]`

GitHub's Linguist list likewise treats `.hujson` as "JSON with Comments"; we found no `.jwcc` entry. JSONC is a close relative but not the same definition: its [draft specification](https://jsonc.org/) makes trailing commas optional for parsers and also ends line comments at a lone carriage return. See [JSON5 vs JSONC](https://json5.dev/compare/jsonc/), and the [VS Code guide](https://json5.dev/tools/vscode/) for JSON5 setup.

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

## Choosing Between Them

Requirement

Lean toward

Why

Lossless conversion to JSON

JWCC

Same object model

Go service that rewrites commented config

JWCC with HuJSON

Syntax tree, patch and formatter

Existing JSON tooling downstream

JWCC

One standardize step

Hand-written files in a JavaScript project

JSON5

Reads like an object literal

Bit masks, limits that may be infinite

JSON5

Hexadecimal and non-finite numbers

Long strings broken across source lines

JSON5

Line continuation

Public API payloads

JSON

Neither extension is needed between machines

You can start narrow and widen later: renaming a JWCC file to `.json5` keeps its value apart from the corner cases above. Going back means quoting keys, converting single quotes and hexadecimal, joining continued strings and deciding what each non-finite number should become. The [migration tutorial](https://json5.dev/tutorials/migration-from-json/) and [format family overview](https://json5.dev/family/) help with the first move.

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

## Common Questions

### Are JWCC and HuJSON the same thing?

In practice, yes. JWCC is the format name from Tao's post; HuJSON, "Human JSON", is Tailscale's name and Go package for it. Hjson is a different format with a similar-sounding name.

### Is JWCC a formal standard?

Its definition is a blog post plus the grammar changes written in the HuJSON package documentation. We know of no RFC for it. The [standards page](https://json5.dev/standards/) covers JSON5's own status.

### Can a JSON5 parser read JWCC?

Yes for normal files. Note that it will also accept things JWCC forbids, so it cannot be used to enforce JWCC.

### Does Tao's post recommend against JSON5?

It explains why the author prefers narrower trade-offs, chiefly his objection to unquoted strings and the difficulty of converting to JSON, and tells readers who like JSON5 to use it.

### Does HuJSON parse JSON5 files?

Only those that use nothing beyond comments and trailing commas. A bare key or single-quoted string is rejected.

## Related Pages

[

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

### JSON5 vs JSONC

The comment format behind VS Code settings.

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

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

### JSON5 vs Hjson

What quoteless strings change.

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

![Idea icon](https://json5.dev/images/icons/idea.png)

### Design Rationale

Why the format includes what it does.

](https://json5.dev/design-rationale/)

## Sources

(16)

1.  [Nigel Tao, JSON With Commas and Comments (2021)](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html)
2.  [tailscale/hujson README](https://github.com/tailscale/hujson)
3.  [hujson package documentation](https://pkg.go.dev/github.com/tailscale/hujson)
4.  [hujson parse.go](https://github.com/tailscale/hujson/blob/master/parse.go)
5.  [hujson parser, Standardize and Minimize tests](https://github.com/tailscale/hujson/blob/master/json_test.go)
6.  [hujson format tests](https://github.com/tailscale/hujson/blob/master/format_test.go)
7.  [hujson patch.go](https://github.com/tailscale/hujson/blob/master/patch.go)
8.  [hujson patch tests](https://github.com/tailscale/hujson/blob/master/patch_test.go)
9.  [hujson commit: reject ambiguous Unicode line separators in comments](https://github.com/tailscale/hujson/commit/b80ff77d)
10.  [hujsonfmt source](https://github.com/tailscale/hujson/blob/master/cmd/hujsonfmt/hujsonfmt.go)
11.  [Tailscale: tailnet policy file](https://tailscale.com/docs/features/tailnet-policy-file)
12.  [RFC 6902, JavaScript Object Notation (JSON) Patch](https://www.rfc-editor.org/rfc/rfc6902)
13.  [RFC 6901, JavaScript Object Notation (JSON) Pointer](https://www.rfc-editor.org/rfc/rfc6901)
14.  [The JSON5 Data Interchange Format, 1.0.0](https://spec.json5.org/)
15.  [JSONC draft specification](https://jsonc.org/)
16.  [GitHub Linguist language list](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml)

Last reviewed: November 29, 2026.
