# JSON5 Editor in a Web App: CodeMirror vs Monaco | JSON5.dev


Source: https://json5.dev/tools/codemirror-monaco/

---

# JSON5 Editor for Web Apps: CodeMirror and Monaco

CodeMirror 6 has a JSON5 package with a parser and a linter. Monaco has a JSON mode you can loosen, and no JSON5 language.

If you are building a settings screen where users type a JSON5 config, you need an editor that does not underline comments and unquoted keys as errors. This page covers what each editor offers out of the box, with package versions and file listings read from installed copies on 12-01-2026.

We ran the Lezer JSON5 parser in Node on a sample with comments, unquoted keys, hex numbers and trailing commas, checked the option names in the Monaco type definitions, and looked for a JSON5 mode in Ace. A comparison table at the end uses real package sizes.

[CodeMirror](#codemirror) [Monaco](#monaco) [Comparison](#compare)

![A settings panel with an embedded JSON5 code editor showing a comment, an unquoted key and a green validation tick](https://json5.dev/img/hero/tools-codemirror-monaco.png)

**TL;DR:** For a JSON5 editor, use CodeMirror 6 with `codemirror-json5` 1.0.3. It highlights, folds, closes brackets and ships a linter. Monaco 0.58.0 has no JSON5 language, but its JSON mode can be told to allow comments and trailing commas, which covers JSONC. Ace 1.45.2 does include a `mode-json5.js`. Note that `codemirror-json5` was last published on 06-28-2023.

[CodeMirror 6](#codemirror) [Lezer Parser Test](#lezer) [Editor Setup](#setup) [Monaco](#monaco) [Ace](#ace) [Comparison](#compare) [FAQ](#faq)

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

## CodeMirror 6: codemirror-json5

The npm package `codemirror-json5` describes itself as "JSON5 support for Codemirror 6". We read its registry record on 12-01-2026: version 1.0.3, MIT license, published 06-28-2023, 27,151 bytes unpacked. Its repository is `dimfeld/codemirror-json5`. It depends on `lezer-json5` 2.0.2 for the parser and on the `json5` package.

The installed package exports five names, which we listed by importing it in Node:

Export

What it is, from the package's type definitions

`json5()`

Language support with the parse cache and cursor path extensions switched on

`json5Language`

The language provider that does the JSON5 parsing

`json5ParseLinter()`

A linter for `@codemirror/lint`. It takes an optional function that checks the parsed object, so you can add your own rules

`json5ParseCache`

A state field holding the parsed value or the syntax error, so other code does not parse the text again

`jsonCursorPath`

A state field with the path inside the object that the cursor is on

In the package source we found that the language definition sets syntax-highlighting tags, indentation, folding, bracket closing for `[`, `{`, double quotes and single quotes, and comment [tokens](https://json5.dev/glossary/#punctuator). The linter imports the `json5` package to report errors, and its error type carries a line and column number.

The package's dependencies do not include `@codemirror/lint` or `@codemirror/commands`, so install the pieces you use yourself. Because the last release is from 2023, treat it as stable rather than actively developed, and test it against the CodeMirror versions you ship. We used `@codemirror/lint` 6.9.8 and `codemirror` 6.0.2 beside it.

![Test icon](https://json5.dev/images/icons/test.png)

## Running the Lezer Parser in Node

`lezer-json5` 2.0.2 is a Lezer grammar for JSON5; its readme says it borrows from the official Lezer JavaScript grammar and a tree-sitter JSON5 grammar. A Lezer parser needs no browser, so we ran it in Node 24.22.1 on 12-01-2026:

``import { parser } from 'lezer-json5'; const sample = `{ // comment name: 'app', /* block */ ports: [8080, 0x1F, .5, +1,], "quoted": true, }`; const tree = parser.parse(sample); tree.iterate({ enter(n) { console.log(n.name, JSON.stringify(sample.slice(n.from, n.to))); }, });``

The tree had these node names, in order: `File`, `Object`, `LineComment`, `Property` with `PropertyName` `name` and `String` `'app'`, `BlockComment`, `Property` with `PropertyName` `ports` and an `Array` holding four `Number` nodes (`8080`, `0x1F`, `.5`, `+1`), then a `Property` for `"quoted"` with a `True` value. We counted error nodes: zero for the sample above.

The check is not vacuous. The broken text `{ a: , b }` produced two error nodes. So the grammar accepts comments, unquoted names, single quotes, hex, a [leading](https://json5.dev/glossary/#leading-decimal-point) dot, a plus sign and a [trailing comma](https://json5.dev/glossary/#trailing-comma), and still marks real mistakes. That says nothing about the cases we did not try, such as Unicode escapes or [line continuations](https://json5.dev/glossary/#line-continuation) in strings.

![Settings icon](https://json5.dev/images/icons/settings.png)

## A Minimal Editor Setup

This follows the package readme, with two additions of ours: a `parent` element so the editor attaches to the page, and `basicSetup` from the `codemirror` package. The installed `basicSetup` includes the default highlight style as a fallback, line numbers, and the lint keymap; without a highlight style the parse tree is there but nothing is colored.

`npm install codemirror codemirror-json5 @codemirror/state @codemirror/view @codemirror/lint`

``import { basicSetup } from 'codemirror'; import { json5, json5ParseLinter } from 'codemirror-json5'; import { linter } from '@codemirror/lint'; import { EditorState } from '@codemirror/state'; import { EditorView } from '@codemirror/view'; const view = new EditorView({ parent: document.querySelector('#editor'), state: EditorState.create({ doc: `{ a_doc: 'goes here' }`, extensions: [ basicSetup, json5(), linter(json5ParseLinter()), ], }), });``

The readme also shows how to read the editor's state from your own code. `state.field(json5ParseCache)` gives an object with `obj` (the parsed value) and `err` (the syntax error, if any), and `state.field(jsonCursorPath)` gives the path under the cursor. A settings screen can use the first to enable a Save button only when `err` is empty, with no second parse.

For rules beyond syntax, such as "port must be a number", pass a function to `json5ParseLinter`. Its type is a function that receives the view and the parsed object and returns diagnostics. A schema checker can sit there; the [schema validation tutorial](https://json5.dev/tutorials/schema-validation/) explains the schema side. We did not run that combination.

![Code icon](https://json5.dev/images/icons/code.png)

## Monaco: JSON Mode, Not JSON5

Monaco is the editor behind VS Code, so the [VS Code guide](https://json5.dev/tools/vscode/) is the user-facing side of this section. We installed `monaco-editor` 0.58.0 (the registry shows it published on 12-01-2026) and looked inside it.

There is no JSON5 language. The package keeps its language definitions in `esm/vs/languages/definitions`, 81 folders from `abap` to `yaml`, including `javascript`, `typescript` and `yaml`, and no folder with `json5` in its name. JSON itself comes from a separate language service under `esm/vs/languages/features/json`. The `esm/vs/basic-languages` folder in 0.58.0 holds one file, `monaco.contribution.js`, and no language folders. We did not look at community packages, since we could not verify any of them.

What you can do is loosen the JSON mode. The type definitions in `monaco.d.ts` list these diagnostic options:

Option

What the type definition says

`validate`

Turns on syntax and schema validation

`allowComments`

"If set, comments are tolerated. If set to false, syntax errors will be emitted for comments."

`comments`

A severity: `'error'`, `'warning'` or `'ignore'`. If not set, `allowComments` decides

`trailingCommas`

The same three severities. "If not set, trailing commas will be reported as errors."

`schemas`

A list of schema URIs, optional `fileMatch` patterns and the schema object itself

`schemaValidation`

Severity of schema problems; `'ignore'` skips schema validation, and `'warning'` is the default

`import * as monaco from 'monaco-editor'; monaco.json.jsonDefaults.setDiagnosticsOptions({ validate: true, allowComments: true, trailingCommas: 'ignore', });`

**Namespace change.** The 0.58.0 type definitions mark `monaco.languages.json` as deprecated and say to use the top-level `json` namespace, which exports `jsonDefaults`. Older tutorials use the old path.

Be clear about what this buys you. Comments and trailing commas stop being errors, which is the JSONC [subset](https://json5.dev/glossary/#superset). The options we found cover nothing for single-quoted strings, unquoted keys, hex numbers or `+` signs, and we did not run the Monaco worker in a browser to see how it treats them. Test your own sample before telling users it works. If you need full JSON5 checking, run a real parser on the text as the user types, as CodeMirror's linter does, and show its message beside the editor. The [online validator](https://json5.dev/tools/online-validator/) shows what such a check should report.

![Search icon](https://json5.dev/images/icons/search.png)

## Ace: It Has a JSON5 Mode

We installed `ace-builds` 1.45.2 and listed the files with `json` in the name under `src-noconflict`: `mode-hjson.js`, `mode-json.js`, `mode-json5.js`, `mode-jsoniq.js` and `worker-json.js`. The `mode-json5.js` file is 11,673 bytes, and it defines `ace/mode/json5_highlight_rules` on top of the JSON highlight rules. The linguist entry for JSON5 on GitHub also names `ace_mode: json5`.

That is the whole of what we checked. We did not run Ace, test its highlighting on the sample, or find out whether its JSON worker validates JSON5; the worker file exists, and that is all we know. Ace is the one editor here with a ready-made JSON5 mode in the package itself, so it is worth a test if you already use it.

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

## Comparison

CodeMirror 6 + codemirror-json5

Monaco

Ace

JSON5 highlighting

Yes, from the Lezer grammar (parser tested in Node)

No JSON5 language. JSON mode with comments allowed

`mode-json5.js` present (not run)

Validation

`json5ParseLinter()`, with a hook for your own checks

JSON diagnostics: `validate`, comment and trailing comma severities

Not verified

Schema support

None built in; add a checker through the linter hook

Built in: `schemas` option in the JSON diagnostics

Not verified

npm unpacked size, read 12-01-2026

`codemirror-json5` 27,151 B, `lezer-json5` 49,058 B, `@codemirror/view` 1,280,040 B, `@codemirror/state` 440,367 B, `@codemirror/language` 291,304 B, `@codemirror/lint` 97,579 B

`monaco-editor` 80,070,496 B

`ace-builds` 58,597,099 B

Last npm release of the JSON5 piece

`codemirror-json5`: 06-28-2023

Not applicable

Part of `ace-builds` 1.45.2 (10-21-2026)

Read the sizes with care. They are the unpacked size of the npm package, taken from `npm view dist.unpackedSize`, which counts every file in the tarball, including type definitions and every language and theme. That is not what a bundler ships to a browser. A CodeMirror editor is assembled from the small pieces you import, and a Monaco build contains only the languages and workers you load. Measure your own bundle before you decide.

The practical choice for a settings screen: pick CodeMirror 6 when the editor is a small part of the page, and you want to parse JSON5 for real. Pick Monaco when you already depend on it or need schema-driven completion, and accept that you are editing JSONC. For the file formats themselves, the [comments in JSON](https://json5.dev/comments-in-json/) page explains which JSON-like formats allow what, and [syntax highlighting](https://json5.dev/tools/syntax-highlighting/) covers read-only code blocks.

## Editor Embedding: Common Questions

### Does CodeMirror 6 have JSON5 support?

Yes, through the community package `codemirror-json5` 1.0.3, which exports `json5()` and `json5ParseLinter()`. It is not part of the core CodeMirror packages.

### Can Monaco edit JSON5?

Not as a named language in 0.58.0. Its JSON mode can allow comments and trailing commas. Unquoted keys and single quotes are not covered by the options we found.

### What are the Monaco option names?

`allowComments`, `comments`, `trailingCommas`, `validate` and `schemas`, all in the diagnostics options of the JSON defaults, as read in `monaco.d.ts` of 0.58.0.

### Does Ace support JSON5?

`ace-builds` 1.45.2 includes `mode-json5.js`. We did not run it.

### How do I validate against a schema?

Monaco has a `schemas` option. In CodeMirror, add your own checker to the linter. See the [schema validation tutorial](https://json5.dev/tutorials/schema-validation/).

### Do I need an editor at all?

For one-off edits, no. The [online validator](https://json5.dev/tools/online-validator/) already checks pasted text in the browser.

## See Also

[![Code icon](https://json5.dev/images/icons/code.png)

### VS Code

Built on Monaco

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

### Schema Validation

Check config shape

](https://json5.dev/tutorials/schema-validation/)[![Security icon](https://json5.dev/images/icons/security.png)

### Online Validator

Paste and check

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

### Syntax Highlighting

Code blocks in docs

](https://json5.dev/tools/syntax-highlighting/)

## Sources

(7)

1.  [codemirror-json5 on npm (1.0.3)](https://www.npmjs.com/package/codemirror-json5) and its [GitHub repository](https://github.com/dimfeld/codemirror-json5)
2.  [lezer-json5 on npm (2.0.2)](https://www.npmjs.com/package/lezer-json5) and its [GitHub repository](https://github.com/dimfeld/lezer-json5)
3.  [monaco-editor on npm (0.58.0)](https://www.npmjs.com/package/monaco-editor)
4.  [ace-builds on npm (1.45.2)](https://www.npmjs.com/package/ace-builds)
5.  [codemirror on npm (6.0.2)](https://www.npmjs.com/package/codemirror)
6.  [@codemirror/lint on npm (6.9.8)](https://www.npmjs.com/package/@codemirror/lint)
7.  [github-linguist: languages.yml (JSON5 entry, `ace_mode: json5`)](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml)

Last reviewed: December 1, 2026.

## Try a Config in the Browser

Paste a config into the validator to see the checks your editor should match.

[Online Validator](https://json5.dev/tools/online-validator/) [All Tools](https://json5.dev/tools/)
