lacspace-schema
JSON → Schema → TypeScript types, and back.
npx lacspace-schema infer data.jsonEverything, in one command
lacspace-schema is a pure, dependency-free codegen toolkit for the JSON ⇄ Schema ⇄ TypeScript loop. Point it at a real API response to derive a merged draft-07 schema (required vs optional properties, unioned types, enum and format detection), generate idiomatic interface/type declarations from either JSON or a schema (with $ref and cycle support, JSDoc examples, and real TS enums), synthesize a valid example instance from any schema, and catch breaking API changes by diffing two schemas — all locally, with nothing sent anywhere.
What's inside
Infer draft-07 schemas
Merge many JSON/NDJSON samples into one schema with required/optional detection.
JSON → TypeScript
Named root, extracted nested interfaces, unions, optionals, readonly, JSDoc.
Schema → TypeScript
Walks $ref/enum/anyOf/const, cycle-safe, string-literal unions or TS enums.
Example generator
Minimal valid instance honouring required/enum/const/format/min-max.
Schema diff
Flags removed/type-changed/newly-required fields as breaking; exits non-zero in CI.
Format & enum detection
email/date-time/date/uri/uuid/ipv4 formats, configurable enum threshold.
Zero-dependency & local
Node built-ins only; reads file, glob, or stdin; no telemetry.
Copy, paste, done
Real commands and snippets — from a one-liner to the typed library.
echo '{"id":1,"email":"a@x.com"}' | npx lacspace-schema inferDraft-07 schema with format:email detected.
npx lacspace-schema types user.json --name User --jsdocExtracts nested interfaces and adds example JSDoc.
npx lacspace-schema types api.schema.json --from schema --enumResolves $ref (cycles safe); emits real TS enums.
npx lacspace-schema example user.schema.jsonA minimal valid fixture instance.
npx lacspace-schema diff v1.schema.json v2.schema.jsonExits 2 when a change breaks consumers.
What people build with it
✓ Bootstrap types from a real API response
✓ Keep TS types in sync with a JSON Schema
✓ Generate fixtures/examples for docs and tests
✓ Guard an API contract in CI via schema diff
Run lacspace-schema today
Free, open-source, no API keys. It's a CLI and a typed library.
npx lacspace-schema infer data.json