lacspace-schema

JSON → Schema → TypeScript types, and back.

terminal
npx lacspace-schema infer data.json
What it does

Everything, 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.

Features

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.

How to use

Copy, paste, done

Real commands and snippets — from a one-liner to the typed library.

Infer a schema from data
terminal
echo '{"id":1,"email":"a@x.com"}' | npx lacspace-schema infer

Draft-07 schema with format:email detected.

JSON → TS types
terminal
npx lacspace-schema types user.json --name User --jsdoc

Extracts nested interfaces and adds example JSDoc.

Schema → TS enums
terminal
npx lacspace-schema types api.schema.json --from schema --enum

Resolves $ref (cycles safe); emits real TS enums.

Example from a schema
terminal
npx lacspace-schema example user.schema.json

A minimal valid fixture instance.

Breaking-change diff in CI
terminal
npx lacspace-schema diff v1.schema.json v2.schema.json

Exits 2 when a change breaks consumers.

Good for

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

Start now

Run lacspace-schema today

Free, open-source, no API keys. It's a CLI and a typed library.

terminal
npx lacspace-schema infer data.json