JSON → SQL

Table:
JSON Input
Loading editor…
SQL Output
Loading editor…

JSON to SQL

Paste a JSON object or array and get ready-to-run SQL — INSERT statements with column types inferred from your data, plus an optional CREATE TABLE. Pick MySQL, PostgreSQL, or SQLite and the identifiers and value formatting adjust to match.

3 dialects
MySQL, PostgreSQL, and SQLite output.
CREATE TABLE
Column types inferred automatically.
Download
Save output as a .sql file.
Client-side
No data is uploaded. Everything runs in your browser.

How JSON Maps to SQL

The converter accepts either a single JSON object (one row) or an array of objects (one row per element). Every unique key across all objects becomes a column, in the order it first appears.

Input JSON:

[
  { "id": 1, "name": "Alice", "active": true },
  { "id": 2, "name": "Bob", "active": false }
]

Generated SQL (MySQL):

CREATE TABLE IF NOT EXISTS `my_table` (
  `id` INT,
  `name` VARCHAR(255),
  `active` TINYINT(1)
);

INSERT INTO `my_table` (`id`, `name`, `active`) VALUES (1, 'Alice', TRUE);
INSERT INTO `my_table` (`id`, `name`, `active`) VALUES (2, 'Bob', FALSE);

Missing keys and null values become SQL NULL. Nested objects and arrays are stored as escaped JSON strings, since plain SQL columns can't hold structured values directly.

Dialect Differences

Switching the dialect changes identifier quoting, boolean literals, and inferred column types:

  • MySQL — identifiers in backticks (column), booleans as TRUE/FALSE, floats as DECIMAL(10,2)
  • PostgreSQL — identifiers in double quotes ("column"), a native BOOLEAN type, floats as NUMERIC(10,2)
  • SQLite — identifiers in double quotes, booleans stored as 0/1 (SQLite has no boolean type), floats as REAL

Column type inference looks at every value in a column across all rows: all-integer columns become INTEGER/INT, columns with any decimal become the dialect's numeric type, all-boolean columns get a boolean type, and strings longer than 255 characters become TEXT instead of VARCHAR(255).

CREATE TABLE and Batch INSERT Options

The CREATE TABLE toggle prepends a CREATE TABLE IF NOT EXISTS statement with inferred column types — useful when loading into an empty database, or turn it off if the table already exists.

The Batch INSERT toggle switches between one INSERT statement per row (easier to read and to run partially) and a single INSERT ... VALUES statement with one tuple per row (fewer statements, faster to execute in bulk). Both produce identical data.

The table name field sanitizes automatically — spaces and symbols become underscores, and a name starting with a digit gets a leading underscore, so the output is always a valid identifier.

Frequently Asked Questions

Can I convert a single JSON object, not just an array?

Yes. A single object is treated as one row and produces one INSERT statement. An array of objects produces one row per element.

How are column types decided?

The tool looks at every value in a column across all rows. All-integer columns become INTEGER/INT, any decimal value makes it a numeric type, all-boolean columns get a boolean type, and long strings (over 255 characters) become TEXT instead of VARCHAR(255).

How are nested objects and arrays handled?

They're serialized to a JSON string and inserted as a quoted text value, since standard SQL columns don't hold structured data. PostgreSQL users can manually change the column type to JSONB afterward if needed.

What happens to missing or null fields?

A key that's missing from a row, or explicitly null, is inserted as SQL NULL.

Does the table name need to be valid already?

No — invalid characters are automatically replaced with underscores, and a name starting with a digit gets a leading underscore added, so the output is always a valid identifier.

Is my JSON uploaded anywhere?

No. The entire conversion runs in your browser with no network requests. Nothing is transmitted.

More Tools