JSON to SQL Converter – CREATE TABLE & INSERT
Turn a JSON array into SQL INSERT statements and a CREATE TABLE command for MySQL, PostgreSQL, SQLite or SQL Server.
JSON Input
SQL
What Is a JSON to SQL Converter?
A JSON to SQL converter turns JSON records into SQL statements you can run in a database. It writes a CREATE TABLE command with a column for every key and INSERT statements for every object, with text safely quoted so names like O'Neil do not break your query.
How to Convert JSON to SQL
- Paste your JSON array, or drop a .json file on the box.
- Choose your database and type a table name.
- Click Convert to SQL, or press Ctrl + Enter.
- Copy the SQL or download it as a .sql file and run it in your database.
Features
- MySQL, PostgreSQL, SQLite and SQL Server syntax and column types.
- Column types are picked from your data: whole numbers, decimals, booleans or text.
- Quotes are escaped and missing values become NULL.
- One multi-row INSERT, or one INSERT per row.
- Runs in your browser. Your data is never uploaded.
Example
[
{ "id": 1, "name": "Emily O'Neil", "balance": 2500.75, "active": true },
{ "id": 2, "name": "James Smith", "balance": 12, "active": false, "city": "Leeds" }
]CREATE TABLE "users" (
"id" BIGINT,
"name" VARCHAR(100),
"balance" DOUBLE PRECISION,
"active" BOOLEAN,
"city" VARCHAR(100)
);
INSERT INTO "users" ("id", "name", "balance", "active", "city") VALUES
(1, 'Emily O''Neil', 2500.75, TRUE, NULL),
(2, 'James Smith', 12, FALSE, 'Leeds');Every key found in any row becomes a column, so the first row gets NULL for the missing city. The apostrophe in O'Neil is doubled, which is how SQL escapes quotes safely.
Dialect Differences
- MySQL quotes names with backticks:
`users`. - PostgreSQL and SQLite use double quotes:
"users". SQLite stores true/false as 1 and 0. - SQL Server uses brackets:
[users], andBITfor booleans.
Before You Run It
- Review the column types and add a
PRIMARY KEY(usually onid). - Increase
VARCHARlengths if your real data has longer text than the sample. - For very large files, split the inserts into batches of a few thousand rows.
- To load a JSON file with SQL itself in PostgreSQL, MySQL, SQLite or SQL Server, see How to Import JSON into a Database.
Frequently Asked Questions
Which databases are supported?
MySQL, PostgreSQL, SQLite and Microsoft SQL Server. The tool uses the right quotes, column types and true/false values for each.
How are column types chosen?
Whole numbers become BIGINT or INTEGER, decimals become DOUBLE or REAL, true/false become BOOLEAN or BIT, and text becomes VARCHAR or TEXT depending on length.
What happens to nested objects?
Nested objects and arrays are stored as JSON text in one column. Many databases can query that text with their JSON functions.
Is my data uploaded?
No. The SQL is generated in your browser.