Converting a database schema into a JSON Schema or TypeScript interface by hand is tedious and error-prone. This tool parses your CREATE TABLE DDL and produces a faithful structural definition you can drop straight into validation middleware, API contracts or typed clients — all in the browser, so proprietary schemas stay private.
How it works
The converter tokenises each CREATE TABLE name ( … ) statement and splits the body on top-level commas (respecting parentheses so DECIMAL(10,2) isn’t broken apart). For every column definition it extracts:
- The name (with surrounding
`,"or[]quotes stripped). - The type and any size/precision, e.g.
VARCHAR(255),DECIMAL(10,2). - Constraints —
NOT NULL,DEFAULT …, inlinePRIMARY KEY.
It then maps each SQL type to its JSON-Schema equivalent:
INT/BIGINT/SMALLINT/SERIAL -> integer
DECIMAL/NUMERIC/FLOAT/REAL -> number
VARCHAR/TEXT/CHAR/UUID -> string (maxLength from the size)
BOOLEAN/BOOL/TINYINT(1) -> boolean
DATE -> string, format: date
TIMESTAMP/DATETIME -> string, format: date-time
A column is added to the schema’s required array when it is NOT NULL or the primary key and has no DEFAULT. For TypeScript output, nullable columns become optional (name?: type).
Tips and notes
- Lines that are table-level constraints (
PRIMARY KEY (...),FOREIGN KEY (...),CONSTRAINT …,INDEX …) are detected and skipped — they aren’t columns. - An unrecognised type falls back to
stringso the output is always valid. TINYINT(1)is treated as boolean to match the common MySQL convention.- The generated JSON Schema uses draft-07 (
$schema,type: object,properties,required).