FormatterHQ

JSON to SQL Converter

Turn an array of JSON records into a CREATE TABLE statement with inferred types and INSERT statements with escaped values, quoted for MySQL, PostgreSQL or SQL Server.

Input JSON
Output SQL
Ready.

How to use the JSON to SQL Converter

  1. Paste an array of JSON objects, upload a .json file, use Load URL, or click Sample.
  2. Enter the Table name and choose Identifier quoting for your database: MySQL backticks, PostgreSQL / ANSI double quotes, SQL Server brackets or None.
  3. Decide whether to Include CREATE TABLE, use a Single multi-row INSERT, and Flatten nested objects.
  4. Click Convert to SQL, review the statements, then Copy them or Download a .sql file.

JSON to SQL seed scripts in one step

Fixtures, API exports and test data often exist as JSON, while the database wants SQL. This JSON to SQL converter reads an array of records and writes a CREATE TABLE statement with a column for every field, followed by INSERT statements with properly quoted and escaped values. Paste the result into your SQL client, a migration or a seed file.

Example

[
  { "id": 1, "name": "O'Brien", "score": 9.5, "active": true, "joined": "2024-03-01", "plan": null },
  { "id": 2, "name": "Kim", "score": 7, "active": false, "joined": "2023-12-24" }
]

With table name users and MySQL quoting:

CREATE TABLE `users` (
  `id` INT,
  `name` VARCHAR(255),
  `score` DECIMAL(18,6),
  `active` BOOLEAN,
  `joined` DATE,
  `plan` VARCHAR(255)
);

INSERT INTO `users` (`id`, `name`, `score`, `active`, `joined`, `plan`) VALUES (1, 'O''Brien', 9.5, TRUE, '2024-03-01', NULL);
INSERT INTO `users` (`id`, `name`, `score`, `active`, `joined`, `plan`) VALUES (2, 'Kim', 7, FALSE, '2023-12-24', NULL);

The apostrophe in O'Brien was doubled, which is the standard SQL way to escape a single quote. The explicit null became NULL, and so did the second record's plan, although that record has no plan key at all: a missing key is written as NULL. Only an empty string in the JSON, "", is written as ''.

How column types are inferred

Each column is typed by looking at all its non-empty values:

Values in the columnType
Whole numbers up to 2,147,483,647INT
Whole numbers, some largerBIGINT
Numbers with any fractionDECIMAL(18,6)
true / false onlyBOOLEAN
Strings like 2024-03-01DATE
Strings like 2024-03-05T10:22:00ZDATETIME (MySQL), TIMESTAMP (ANSI), DATETIME2 (SQL Server)
Other strings, mixed types or no valuesVARCHAR(255), or TEXT when a value is longer than 255 characters

The types are a starting point. Add primary keys, NOT NULL constraints and tighter lengths before using the table in production.

Options

  • Table name – used in both statements; my_table if left empty.
  • Identifier quoting – wraps table and column names in backticks (MySQL, MariaDB), double quotes (PostgreSQL, SQLite and ANSI SQL) or square brackets (SQL Server). None leaves simple names bare but still double-quotes names with spaces, dots or symbols. Bare names can collide with reserved words such as order or user, so quoting is the safer default.
  • Include CREATE TABLE – untick it when the table already exists and you only need rows.
  • Single multi-row INSERT – writes one INSERT … VALUES (…), (…); statement instead of one per record. It is shorter and usually loads faster; for very large data sets, split it into chunks your database accepts.
  • Flatten nested objects – nested fields become columns named with dots, such as meta.plan. With it off, nested objects and arrays are inserted as JSON text, for example '{"plan":"pro"}', which you can store in a JSON or JSONB column after changing the type.

Dialect notes

  • SQL Server has no BOOLEAN type and no TRUE/FALSE literals. Change the column to BIT and the values to 1 and 0.
  • PostgreSQL does not accept backticks. Choose the ANSI option so identifiers use double quotes.
  • Dotted column names from flattening are legal when quoted, but awkward to type in queries. Rename them to meta_plan in the JSON or the output if you prefer.
  • MySQL and backslashes. Only single quotes are escaped. MySQL treats a backslash in a string as an escape character by default, so a value such as a Windows path can change meaning. Double the backslashes or enable the NO_BACKSLASH_ESCAPES SQL mode before loading such data.

Before you run the script

  1. Check numeric and date columns for empty strings. A missing key becomes NULL, but a value of "" is written as '', and PostgreSQL and MySQL in strict mode reject that row for an INT or DATE column. Change those values to null in the JSON.
  2. Look at the VARCHAR(255) columns. A column that mixes numbers and text falls back to a string type, which may hint at inconsistent data in the source.
  3. Run the statements inside a transaction or against a scratch database first, so a failed row does not leave the table half filled.

Tidy long scripts with the SQL formatter. If your data is a spreadsheet export, CSV to SQL does the same job, and SQL to JSON turns INSERT statements back into records.

Privacy

The statements are generated in your browser; your JSON is not uploaded and nothing is executed against any database. Load URL and Save & Share are the only features that reach our server.

Frequently asked questions

How are single quotes in JSON strings escaped?
Each single quote is doubled, so O'Brien becomes 'O''Brien'. This works in MySQL, PostgreSQL, SQL Server and SQLite. Backslashes are not escaped, which matters only in MySQL with its default SQL mode.
Is a missing field written as NULL or as an empty string?
As NULL. An explicit null in the JSON and a key that is absent from a record both produce NULL. Only an empty string value ("") is written as ''; change it to null if the column should be NULL.
Can I generate SQL for PostgreSQL?
Yes. Choose PostgreSQL / ANSI "quotes" under Identifier quoting. Timestamp columns are then typed TIMESTAMP, and the BOOLEAN, TRUE and FALSE output is valid PostgreSQL.
Does it create a primary key or indexes?
No. The CREATE TABLE statement lists columns and types only. Add PRIMARY KEY, NOT NULL and index definitions yourself before running it.
What JSON shape does the converter expect?
An array of objects works best, and a wrapper such as {"rows": [...]} is unwrapped automatically. A single object becomes one row.

Last updated October 3, 2026

Related tools