Code Beautifier

JSON to SQL

Convert an array of JSON objects into CREATE TABLE and INSERT statements, flattening nested objects and storing arrays as JSON.

Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

Dialect:
Rows per INSERT:
json
Formatted Outputsql

Options

OptionDescription
DialectSets how identifiers are quoted, which types are used, and how booleans are written.
Table nameName used in the CREATE TABLE and INSERT statements.
Include CREATE TABLETurn off when the table already exists and you only need the inserts.
Flatten nested objectsOn, user.email becomes its own column. Off, the whole nested object is stored as JSON in one column.
Rows per INSERTMulti-row inserts load faster, but very large batches can exceed a server's packet limit.

FAQ

What happens to nested objects?

They're flattened into dotted column names, so user.email becomes a column called user.email, quoted for your dialect. Turn flattening off to keep the object together and store it as JSON in a single column.

How are arrays stored?

As JSON text, since a relational column can't hold a list. In PostgreSQL you can change the generated column type to JSONB, or split the values into a separate table if you need to query them.

What if some objects are missing keys?

The column list is the union of every object's keys, in the order they first appear, and any record without a key gets NULL for it. That keeps one INSERT shape for all rows.

How are column types decided?

By the values: whole numbers become integers, decimals numeric, true and false boolean, ISO dates and timestamps their date types, and anything mixed falls back to text.

Does the input have to be an array?

A single object works too and becomes one row. Arrays of plain values, such as [1, 2], can't become rows because there are no column names to use.