Registry / testing / json-lint-d-ts

json-lint-d-ts

JSON →
library1.2.2jsnpmunverified

Lint JSON files against TypeScript declaration files. Current stable version is 1.2.2, released optionally. It validates JSON files by comparing them to .d.ts definitions, ensuring type safety without running TypeScript. Supports generation of .d.ts files from JSON samples (via quicktype) and from HTTP endpoints. Key differentiator: unlike JSON Schema validators, it uses TypeScript type definitions directly as the schema source.

npm install json-lint-d-ts
INSTALL
IMPORT
SIG · JSON-LINT-D-TS
J
json-lint-d-ts
testingjavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

validate
import { validate } from "json-lint-d-ts";
const validate = require("json-lint-d-ts").validate;
ESM default; CommonJS require works but destructuring is not supported directly.
generate
import { generate } from "json-lint-d-ts";
import { generate } from "json-lint-d-ts/generate";
Both validate and generate are top-level exports.
generateAsync
import { generateAsync } from "json-lint-d-ts";
import { generateAsync } from "json-lint-d-ts/src/generateAsync";
Available since v1.2.0 for HTTP-based generation.

Validates a JSON file against a TypeScript declaration file using the validate function.

import { validate } from "json-lint-d-ts"; const result = validate([ ["./hello.json", "./hello.d.ts"], ]); // Result shows any type errors console.log(result);
json-lint-d-ts --version
Debug
Known issues
gotcha.d.ts file must define a 'type Root' for validation to work; otherwise validation may silently succeed or fail unexpectedly.
fix
Ensure your .d.ts file exports a type named Root. For example: type Root = YourInterface;
affects: >=1.0.0
deprecatedgenerate function uses quicktype under the hood and may have breaking changes when quicktype updates.
fix
Monitor quicktype changelog for breaking changes, or pin quicktype version if needed.
affects: >=1.1.0
gotchaValidation errors are returned as strings, not structured objects. Parsing error messages for programmatic use is brittle.
fix
Use string matching or regex to extract error details; consider wrapping validate in a custom parser.
affects: >=1.0.0
gotchagenerateAsync does not support Bearer tokens or custom headers for HTTP endpoints; only raw URL fetch without authentication.
fix
Pre-fetch data with your own fetch() and pass the JSON body directly to generate.
affects: >=1.2.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'Symbol(quick-type)')
Missing or incompatible quicktype version when using generate.
fix
Install quicktype as a peer dependency: yarn add -D quicktype
Error: No type Root found in declaration file.
The .d.ts file does not define a type named Root.
fix
Add `type Root = YourMainType;` to the declaration file.
TypeError: validate(...).then is not a function
Treating validate as async when it is synchronous.
fix
Use result = validate([...]) without await; validate returns an array directly.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
typescriptoptionalUsed for type checking JSON against .d.ts files during validation
quicktypeoptionalUsed for generating TypeScript declarations from JSON samples
Agent activity
4 hits · last 30 days
node
4
Resources
json-lint-d-ts — npm install json-lint-d-ts · libregistry