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

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.

Specification icon

What JWCC Is

Nigel Tao published "JSON With Commas and Comments" 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 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.

The idea predates the name. The first commit in Tailscale's hujson repository 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

What JWCC Leaves Out

FeatureJSON5JWCCReason or behavior
CommentsYesYesOne of the two additions
Trailing commaYesYesThe other; a lone [,] is an error in both
Unquoted keysYesNoinvalid character 'n' at start of object name
Single-quoted stringsYesNoConsidered and dropped, per the post
Multiline stringsYesNoConsidered and dropped
Leading +YesNoinvalid literal: +1000
Hexadecimal, .5, 5.YesNoNumbers follow JSON
NaN, InfinityYesNoKeeps the JSON object model
Extra escapes such as \v and \x41YesNoStrings follow JSON
Extra whitespace charactersYesNoOnly space, tab, CR and LF
# commentsNoNoNot valid JavaScript
Missing commasNoNoNot valid JavaScript
Duplicate keys prohibitedNot prohibitedNot prohibitedJWCC keeps JSON behavior on purpose

The quoted error messages come from the test table in 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 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.

Layers icon

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 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 U+2028 and U+2029.

Input, with escapes standing for the raw charactersjson5 2.2.3 resultUnder 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, 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

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:

InputResult
{ 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; 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

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 covers other directions.

Go logo

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.

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.

Text format icon

Standardize, Minimize and Format

OperationEffectOutput is strict JSON
StandardizeReplaces comments and trailing commas with spaces, keeping line numbers and byte offsetsYes
MinimizeRemoves whitespace, comments and trailing commasYes
FormatApplies an opinionated layout and keeps commentsOnly if the input already was
IsStandardReports whether comments and trailing commas are absentNot 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 covers JSON5 formatters.

Edit icon

Patching Without Losing Comments

Value.Patch applies a JSON Patch (RFC 6902) 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), 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

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 logoIn 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 makes trailing commas optional for parsers and also ends line comments at a lone carriage return. See JSON5 vs JSONC, and the VS Code guide for JSON5 setup.

Checklist icon

Choosing Between Them

RequirementLean towardWhy
Lossless conversion to JSONJWCCSame object model
Go service that rewrites commented configJWCC with HuJSONSyntax tree, patch and formatter
Existing JSON tooling downstreamJWCCOne standardize step
Hand-written files in a JavaScript projectJSON5Reads like an object literal
Bit masks, limits that may be infiniteJSON5Hexadecimal and non-finite numbers
Long strings broken across source linesJSON5Line continuation
Public API payloadsJSONNeither 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 and format family overview help with the first move.

Question icon

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