UTILS.
100% in-browser
🗄

JSON to SQL CREATE TABLE

Infer a SQL CREATE TABLE (and optional INSERTs) from a JSON array of objects, picking column types automatically for MySQL, PostgreSQL, or SQLite.

— output appears here —

About this tool

The JSON to SQL CREATE TABLE tool reads a JSON array of objects (or a single object) and infers a matching SQL table definition, choosing each column's type from the values it actually sees. It runs entirely in your browser — the JSON is parsed with the native JSON.parse and never leaves your device — so you can paste an API dump or a database export and scaffold a table in one step.

Column types are inferred per field across every row: values that are all whole numbers become INT (BIGINT when any value exceeds 2,147,483,647), numbers with decimals become DECIMAL(p,s) sized to the widest integer and fraction digit counts you supplied (or DOUBLE / REAL when you pick the float mode), booleans map to TINYINT(1)/BOOLEAN, ISO 8601 strings map to DATETIME or DATE, nested objects and arrays become JSON/JSONB, and remaining strings become VARCHAR(N) where N is the next power of two above the longest value (TEXT once that exceeds 255). A column that is null or missing in any row is left NULLABLE; otherwise it is NOT NULL. A unique, non-null column named id or uuid is promoted to the PRIMARY KEY, with AUTO_INCREMENT / SERIAL / AUTOINCREMENT added for integer keys.

A dialect toggle rewrites the types for MySQL, PostgreSQL (SERIAL, JSONB, TIMESTAMP, DOUBLE PRECISION), or SQLite (INTEGER / REAL / TEXT affinities) and quotes identifiers with the right delimiter (backticks for MySQL, double quotes elsewhere). Turn on the INSERTs option to also emit one INSERT statement per row, with strings, booleans, numbers, and JSON values escaped and quoted for the chosen dialect.

Frequently asked questions

What input does it expect?
A JSON array of flat objects, such as rows from an API or export, or a single JSON object which is treated as a one-row table. All keys across the rows are unioned to form the columns; non-object elements are rejected.
How are column types chosen?
Per column, from every value seen: all-integer to INT/BIGINT, decimals to DECIMAL(p,s) or DOUBLE, booleans to TINYINT(1)/BOOLEAN, ISO date-times to DATETIME/DATE, objects/arrays to JSON, and other strings to VARCHAR(N) (TEXT above 255 chars).
Which SQL dialects are supported?
MySQL, PostgreSQL, and SQLite. The dialect toggle rewrites the type names (SERIAL, JSONB, TIMESTAMP for Postgres; INTEGER/REAL/TEXT affinities for SQLite) and uses the correct identifier quoting and auto-increment syntax.
How is the primary key decided?
If a column named id or uuid is present and non-null in every row with unique values, it is marked PRIMARY KEY. An integer key also gets AUTO_INCREMENT (MySQL), SERIAL (PostgreSQL), or AUTOINCREMENT (SQLite).

More tools