Modern JSON parser extending JSON5 with ES2015–2025 features and year‑pinned APIs.
@cldmv/jsonv is a static data format: JSON5 plus modern literals, with features gated by ECMAScript year modules. It adds internal references (file‑scoped, defined‑before‑use) and forbids executable syntax (no functions, classes, computed keys, or shorthand props).
- JSON5 superset (comments, trailing commas, single quotes, hex, etc.)
- Year‑pinned APIs:
@cldmv/jsonv/2011,/2015,/2020,/2021(2022–2025 re‑export 2021) - Modern literals: binary/octal, BigInt, numeric separators
- Internal references and template interpolation (ES2015+), including forward references
- Diagnostics:
diagnose()andinfo()for year + feature detection - Stringify with json/json5/jsonv modes, BigInt strategies, and raw JSON passthrough
- Dynamic year loading and resolver utilities (
loadYear,resolveYear) - Zero dependencies, hand‑written parser
npm install @cldmv/jsonvimport{parse,stringify}from"@cldmv/jsonv";constconfig=parse(`{ port: 8080, host: "localhost", url: `http://${host}:${port}`, maxConnections: 1_000_000, bigValue: 9007199254740992n}`);consttext=stringify(config);Pin a year for stable grammar rules:
import{parse}from"@cldmv/jsonv/2021";// numeric separators + BigIntimport{parseasparse2015}from"@cldmv/jsonv/2015";// binary/octal + templatesimport{parseasparse2011}from"@cldmv/jsonv/2011";// JSON5 baseSee docs/feature-matrix.md and docs/versioning-and-exports.md.
Main entry: src/index.mts
year: 2011–2025 (defaults to latest)mode:jsonv | json5 | jsonallowInternalReferences: defaulttruestrictBigInt: requirenfor unsafe integers (defaultfalse)strictOctal: require0o(reject legacy0755, defaultfalse)tolerant: collect multiple errorspreserveComments: keep comment nodes in results
mode:jsonv | json5 | jsonbigint:native | string | objectsingleQuote,trailingComma,unquotedKeyspreserveNumericFormatting
Full types: src/api-types.mts
{ port: 8080, backup: port, url: `http://${host}:${port}` }
Rules: file‑scoped only, forward references supported, no circular refs.
import{loadYear,getLoadedYear}from"@cldmv/jsonv/loader";import{resolveYear,isPublishedYear,getPublishedYears}from"@cldmv/jsonv/year-resolver";constjsonv2023=awaitloadYear(2023);// resolves to 2021constresolved=getLoadedYear(2017);// 2015constpublished=getPublishedYears();// [2011, 2015, 2020, 2021]constisPublished=isPublishedYear(2021);// trueconstnearest=resolveYear(2024);// 2021diagnose() returns detected year/features + compatibility flags (json, json5).
info() returns only detected year + parsed value.
- Test runner:
npm test(Vitest) - Fixtures: tests/fixtures/ with
features/andviolations/per year - See tests/fixtures/README.md for layout
- ESLint plugin:
plugins/eslint-plugin-jsonv(build vianpm run build:plugin) - VS Code language support:
plugins/vscode-jsonv
npm run dev # uses src/ via json-dev condition
npm run build # clean → ts → types → years → cjs → plugin
npm test# Vitest
npm run lint # ESLint v9 configApache-2.0