b2KIT

SQL DDL to JSON Schema

Convert SQL CREATE TABLE statements to JSON Schema definitions with type mapping and constraints.

Tested tool guide Tested browser tools Checked August 16, 2026

What SQL DDL to JSON Schema does, with a checked example

Paste a CREATE TABLE statement and the tool returns a JSON Schema document that describes the shape of one row of that table. Everything happens in the browser; the DDL never leaves your machine. It reads the statement, maps each column type (INTEGER to integer, VARCHAR to string, BOOLEAN to boolean) and carries constraints into schema keywords: NOT NULL columns land in the required array, a length argument becomes maxLength, and a DEFAULT value becomes the default keyword. The surprise is nullability: SQL columns are nullable by default, and a schema that types such a column as string rejects the null values the database happily stores.

Worked example

A concrete input and expected output from the current implementation.

Input

CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  age INTEGER
);

Expected output

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string", "maxLength": 50 },
    "age": { "type": "integer" }
  },
  "required": ["id", "name"]
}

VARCHAR(50) becomes a string capped at 50 characters, INTEGER maps to integer, and the two columns the database will not leave empty - id (PRIMARY KEY) and name (NOT NULL) - are collected into the required array. age stays out of required because a column without NOT NULL may hold NULL, mirroring the table's own rule.

How the result is produced

1

Parsing the statement

The tool reads the DDL, finds the table name, and splits the column list into one entry per column. Each entry yields its type name, any parenthesized arguments such as the 50 in VARCHAR(50), and its constraint keywords, which together determine the property's schema: the SQL type selects the JSON Schema type, and the length argument becomes maxLength.

2

Constraint translation

NOT NULL and PRIMARY KEY columns are collected into the required array, DEFAULT values are copied into the default keyword, and a CHECK that lists fixed values may become an enum. What JSON Schema has no keyword for - indexes, foreign keys, cross-row uniqueness, triggers - is dropped. The result validates one record's shape; it is not a reproduction of the table.

Good uses

  • Building validators for an API whose database tables already exist: paste the DDL and feed the output to a JSON Schema validator that checks request and response payloads.
  • Documenting a data contract from a DDL export when you cannot query the source database directly, to share the record shape with another team building against the same data.
  • Starting a migration from SQL rows to JSON documents in a document store or event stream, where the generated schema seeds the validation rules for the new format.

Limits and checks

  • [object Object]
  • [object Object]
  • [object Object]

Common questions

Can I paste several CREATE TABLE statements at once?

Some converters accept multiple statements and return one schema per table; others handle only one and silently ignore or error on the rest. Separate statements with semicolons and confirm every table appears in the output. If one is missing, convert it on its own rather than assuming it was skipped for a reason.

Will the schema accept exactly the data my database accepts?

No. required checks that a property is present, not that it is non-null, default is only an annotation that validators do not enforce, and foreign keys and cross-row uniqueness cannot be expressed in JSON Schema. Values the database fills in itself, such as auto-increment ids and current-timestamp defaults, also count against required, so expect some edits before the schema matches real data.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools