{"id":13435,"library":"lezer-json5","title":"Lezer JSON5 Parser","description":"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.","status":"maintenance","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/dimfeld/lezer-json5","tags":["javascript","lezer","codemirror","json5","typescript"],"install":[{"cmd":"npm install lezer-json5","lang":"bash","label":"npm"},{"cmd":"yarn add lezer-json5","lang":"bash","label":"yarn"},{"cmd":"pnpm add lezer-json5","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for the generated Lezer LR parser.","package":"@lezer/lr","optional":false}],"imports":[{"note":"This package is designed for modern ESM environments, especially with CodeMirror 6.","wrong":"const json5 = require('lezer-json5');","symbol":"json5","correct":"import { json5 } from 'lezer-json5';"},{"note":"The parser is a named export, not a default export.","wrong":"import json5 from 'lezer-json5';","symbol":"json5","correct":"import { json5 } from 'lezer-json5';"},{"note":"Required to integrate the Lezer parser with CodeMirror 6 as a language extension.","symbol":"LanguageSupport","correct":"import { LanguageSupport } from '@codemirror/language';"}],"quickstart":{"code":"import { EditorState } from '@codemirror/state';\nimport { EditorView, basicSetup } from 'codemirror';\nimport { json5 } from 'lezer-json5';\nimport { LanguageSupport } from '@codemirror/language';\n\nconst json5Doc = `\n// This is a JSON5 document\n{\n  key: \"value\", // Unquoted keys and comments are allowed\n  anotherKey: [\n    1,\n    2, // Trailing commas are fine\n    3,\n  ],\n  \"quoted-key\": 0xAF, // Hexadecimal numbers\n  lastValue: .5e-2, // Leading/trailing decimal points, exponential notation\n  true,\n  false,\n  null,\n}\n`;\n\nconst state = EditorState.create({\n  doc: json5Doc,\n  extensions: [\n    basicSetup, // Provides essential editor functionality (line numbers, history etc.)\n    new LanguageSupport(json5()), // Activates JSON5 syntax highlighting and language features\n  ],\n});\n\nconst editorParent = document.createElement('div');\ndocument.body.appendChild(editorParent);\n\nnew EditorView({\n  state,\n  parent: editorParent,\n});\n\nconsole.log('CodeMirror 6 editor with JSON5 support initialized.');\n","lang":"typescript","description":"Demonstrates setting up a basic CodeMirror 6 editor with `lezer-json5` for syntax highlighting and language support for JSON5 documents."},"warnings":[{"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.","message":"Breaking 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always use the `lezer-json5` parser for JSON5 content. Do not substitute with a plain JSON parser if JSON5 features are present.","message":"JSON5 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `import` syntax in a CommonJS (`require`) environment without proper transpilation or Node.js ESM configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Ensure you call the `json5` function when providing it to `LanguageSupport`: `new LanguageSupport(json5())`.","cause":"Incorrectly importing the `json5` parser. It is usually a function that needs to be called to create the language extension for CodeMirror.","error":"TypeError: (0, _lezer_json5__WEBPACK_IMPORTED_MODULE_2__.json5) is not a function"},{"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.","cause":"Potentially using an outdated TypeScript version, incorrect `tsconfig.json` settings, or a bundler that mishandles module resolution, leading to type declaration issues.","error":"Property 'json5' does not exist on type 'typeof import(\"lezer-json5\")'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}