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-json5Verified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic CodeMirror 6 editor with `lezer-json5` for syntax highlighting and language support for JSON5 documents.
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.
Always use the `lezer-json5` parser for JSON5 content. Do not substitute with a plain JSON parser if JSON5 features are present.
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.
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.
Ensure you call the `json5` function when providing it to `LanguageSupport`: `new LanguageSupport(json5())`.
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.