Registry / serialization / lezer-json5

lezer-json5

JSON →
library2.0.2jsnpmunverified

lezer-json5 is a Lezer grammar designed for parsing JSON5 (JavaScript Object Notation, Fifth Edition) syntax. JSON5 extends standard JSON by adding features like comments, unquoted object keys, trailing commas, and single-quoted strings, making configuration files more human-readable. This package, currently at version 2.0.2, integrates seamlessly with CodeMirror 6, providing robust syntax highlighting and language-aware editing capabilities for JSON5 documents. While the package was last published three years ago, it remains a stable and functional solution for JSON5 parsing within the Lezer/CodeMirror ecosystem, leveraging principles from the official Lezer JavaScript grammar. Its slow release cadence suggests a mature grammar that is unlikely to require frequent updates unless core Lezer APIs or the JSON5 specification undergo significant changes. It differentiates itself by offering incremental parsing specific to the JSON5 specification, which is crucial for performance in large editor instances.

npm install lezer-json5
INSTALL
IMPORT
SIG · LEZER-JSON5
L
lezer-json5
serializationjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

json5
import { json5 } from 'lezer-json5';
const json5 = require('lezer-json5');
This package is designed for modern ESM environments, especially with CodeMirror 6.
json5
import { json5 } from 'lezer-json5';
import json5 from 'lezer-json5';
The parser is a named export, not a default export.
LanguageSupport
import { LanguageSupport } from '@codemirror/language';
Required to integrate the Lezer parser with CodeMirror 6 as a language extension.

Demonstrates setting up a basic CodeMirror 6 editor with `lezer-json5` for syntax highlighting and language support for JSON5 documents.

import { EditorState } from '@codemirror/state'; import { EditorView, basicSetup } from 'codemirror'; import { json5 } from 'lezer-json5'; import { LanguageSupport } from '@codemirror/language'; const json5Doc = ` // This is a JSON5 document { key: "value", // Unquoted keys and comments are allowed anotherKey: [ 1, 2, // Trailing commas are fine 3, ], "quoted-key": 0xAF, // Hexadecimal numbers lastValue: .5e-2, // Leading/trailing decimal points, exponential notation true, false, null, } `; const state = EditorState.create({ doc: json5Doc, extensions: [ basicSetup, // Provides essential editor functionality (line numbers, history etc.) new LanguageSupport(json5()), // Activates JSON5 syntax highlighting and language features ], }); const editorParent = document.createElement('div'); document.body.appendChild(editorParent); new EditorView({ state, parent: editorParent, }); console.log('CodeMirror 6 editor with JSON5 support initialized.');
Debug
Known issues
breakingBreaking changes in core Lezer packages (`@lezer/common`, `@lezer/lr`) or CodeMirror 6 major versions can potentially impact `lezer-json5` functionality, requiring updates to maintain compatibility. Users should consult the Lezer and CodeMirror changelogs.
fix
Ensure your `@lezer/*` and `codemirror` packages are compatible with the `lezer-json5` version, typically by updating to the latest stable versions of all related CodeMirror/Lezer packages.
affects: >=1.0.0
gotchaJSON5 is a superset of JSON. Attempting to parse JSON5 content with a standard JSON parser (e.g., `lezer-json` or `JSON.parse`) will result in syntax errors for valid JSON5 features like comments, unquoted keys, or trailing commas.
fix
Always use the `lezer-json5` parser for JSON5 content. Do not substitute with a plain JSON parser if JSON5 features are present.
affects: >=1.0.0
gotchaThe package has not been updated in approximately three years. While it indicates stability, it also means that very recent changes to the JSON5 specification (if any) or major advancements in the Lezer parsing system might not be immediately incorporated.
fix
For mission-critical applications or if you require the absolute latest JSON5 features, review the GitHub repository for any unreleased updates or forks. Otherwise, assume the current feature set is stable.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax in a CommonJS (`require`) environment without proper transpilation or Node.js ESM configuration.
fix
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) or use a bundler like Webpack/Rollup/ESBuild that transpiles ESM imports for your target environment. This package is ESM-first.
TypeError: (0, _lezer_json5__WEBPACK_IMPORTED_MODULE_2__.json5) is not a function
Incorrectly importing the `json5` parser. It is usually a function that needs to be called to create the language extension for CodeMirror.
fix
Ensure you call the `json5` function when providing it to `LanguageSupport`: `new LanguageSupport(json5())`.
Property 'json5' does not exist on type 'typeof import("lezer-json5")'
Potentially using an outdated TypeScript version, incorrect `tsconfig.json` settings, or a bundler that mishandles module resolution, leading to type declaration issues.
fix
Verify that your TypeScript version is up-to-date and your `tsconfig.json` has `"moduleResolution": "Bundler"` or `"NodeNext"` (depending on your setup) and `"module": "ESNext"` or similar settings that correctly resolve ESM type declarations.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
@lezer/lrrequiredRuntime dependency for the generated Lezer LR parser.
Agent activity
2 hits · last 30 days
node
2
Resources
lezer-json5 — npm install lezer-json5 · libregistry