How to use the JSON to SQL
- 1
Paste an array of objects
Each object becomes a row; keys from all objects become columns.
- 2
Name the table and pick a database
Choose MySQL/MariaDB, PostgreSQL, SQLite or SQL Server.
- 3
Choose output pieces
Keep or drop CREATE TABLE, and pick one multi-row INSERT or one INSERT per row.
- 4
Review, then run
Check the column types, add a primary key, and run the script in a test database first.
Features
Dialect-specific types
The same data becomes DOUBLE in MySQL, DOUBLE PRECISION in PostgreSQL, REAL in SQLite and FLOAT in SQL Server.
Date detection
YYYY-MM-DD strings become DATE; strings starting with a date and time become DATETIME, TIMESTAMPTZ or DATETIME2.
NOT NULL inference
A column gets NOT NULL only when every row has a non-null value for it.
Sized VARCHAR
Text columns are sized from the longest value (in steps of 50, up to 255), or TEXT when longer.
JSON columns
Arrays and nested objects go into JSON, JSONB, TEXT or NVARCHAR(MAX) depending on the database.
Local
Nothing is sent to a server or a database.
Who uses it โ and for what
Developers
Seed a local or test database from JSON fixtures.
Data migrations
Move a small JSON export into a relational table.
SQL learners
Get a practice table with real-looking data in seconds.
Analysts
Load an API response into SQLite to query it with SQL.
Column types from your data
The converter scans every object to collect all column names and picks a type per column: whole numbers become INTEGER or BIGINT, decimals DOUBLE/REAL, true/false BOOLEAN (or BIT on SQL Server), ISO dates DATE/TIMESTAMP, and text VARCHAR(n) sized to the longest value (or TEXT). Nested objects and arrays are stored as JSON text (JSON/JSONB where the database supports it). Missing values become NULL.
Safe, dialect-aware output
Identifiers are quoted the right way for each database (backticks for MySQL, double quotes for PostgreSQL and SQLite, square brackets for SQL Server) and string values are escaped by doubling single quotes. Multi-row INSERTs are much faster to load; one-per-row is easier to edit. Review types before running in production โ add primary keys, indexes and constraints as needed.
Everything runs in your browser โ your code and data are never uploaded, so it is safe to paste private config files and API responses.
Checks before you run the script
The generator infers a reasonable table from a sample, but a sample is not a specification. Before running the output anywhere that matters, go through this list:
- Add a primary key. No key is created. Add
PRIMARY KEYto the natural key (heresku) or an identity column. - Widen short text columns. VARCHAR sizes come from the longest value in your sample (1.5 ร the length, rounded up to a multiple of 50, at least 50). A later product name longer than 50 characters would be rejected or truncated, depending on the database and its strict settings.
- Money. Prices become floating-point types. Change them to
DECIMAL(10,2)(orNUMERIC) so totals add up exactly. - Timestamps with a Z. ISO values like
2026-11-20T10:00:00Zare inserted as they are. PostgreSQLโsTIMESTAMPTZunderstands them; MySQLโsDATETIMEand SQL ServerโsDATETIME2may reject or misread theT/Zform depending on version and settings, so convert them to'2026-11-20 10:00:00'if you see errors. - Mixed columns. If a key holds numbers in some rows and text in others, the column becomes VARCHAR but the numbers are still written unquoted. Most databases convert them, but quoting the JSON values consistently is cleaner.
One INSERT or many?
| One multi-row INSERT | One INSERT per row | |
|---|---|---|
| Speed | Much faster to load โ one statement, one round trip | Slower for big files |
| Failure behaviour | One bad row rejects the whole statement | Only the bad row fails (unless wrapped in a transaction) |
| Editing by hand | Harder | Easy to delete or tweak individual rows |
| Limits | SQL Server allows at most 1,000 rows in one VALUES list; MySQL is limited by max_allowed_packet | None in practice |
For more than a few thousand rows, the databaseโs bulk loader โ COPY in PostgreSQL, LOAD DATA in MySQL, .import in the SQLite shell โ is far faster than any INSERT script. Convert the JSON with JSON to CSV and load that instead.
Worked examples
Products into PostgreSQL
Input (two rows):
[{"sku": "KUR-01", "name": "Men's Kurta", "price": 799, "mrp": 999.5, "in_stock": true,
"launched": "2026-08-15", "updated_at": "2026-11-20T10:00:00Z", "sizes": ["M", "L"], "note": null},
{"sku": "SAR-07", "name": "Silk Saree", "price": 4599, "mrp": 5200, "in_stock": false,
"launched": "2025-12-01", "updated_at": "2026-11-21 09:30:00", "sizes": []}]Output for table products, PostgreSQL:
CREATE TABLE "products" (
"sku" VARCHAR(50) NOT NULL,
"name" VARCHAR(50) NOT NULL,
"price" INTEGER NOT NULL,
"mrp" DOUBLE PRECISION NOT NULL,
"in_stock" BOOLEAN NOT NULL,
"launched" DATE NOT NULL,
"updated_at" TIMESTAMPTZ NOT NULL,
"sizes" JSONB NOT NULL,
"note" TEXT
);
INSERT INTO "products" ("sku", "name", "price", "mrp", "in_stock", "launched", "updated_at", "sizes", "note") VALUES
('KUR-01', 'Men''s Kurta', 799, 999.5, TRUE, '2026-08-15', '2026-11-20T10:00:00Z', '["M","L"]', NULL),
('SAR-07', 'Silk Saree', 4599, 5200, FALSE, '2025-12-01', '2026-11-21 09:30:00', '[]', NULL);The apostrophe in Men's is doubled. mrp mixed 999.5 and 5200, so the decimal type wins. note was null or missing everywhere, so it has no type evidence and falls back to nullable TEXT.
The same data in the other dialects
| Column | MySQL / MariaDB | SQLite | SQL Server |
|---|---|---|---|
| sku | VARCHAR(50) | TEXT | NVARCHAR(50) |
| price | INT | INTEGER | INT |
| in_stock | BOOLEAN, values TRUE/FALSE | INTEGER, values 1/0 | BIT, values 1/0 |
| updated_at | DATETIME | TEXT | DATETIME2 |
| sizes | JSON | TEXT | NVARCHAR(MAX) |
| note | TEXT | TEXT | NVARCHAR(255) |
Identifiers are quoted with backticks in MySQL and square brackets in SQL Server, and every SQL Server string literal gets the N prefix (N'Silk Saree') so Unicode text such as Hindi names is stored correctly.
Pro tips
- Wrap the script in BEGIN; โฆ COMMIT; so a failure part-way leaves the table untouched.
- In SQLite, booleans are stored as 1 and 0 and dates as text; that is normal for SQLite, not a mistake.
- Generated SQL is for loading data you trust. In application code, always use parameterised queries instead of building SQL strings.
Glossary
- DDL
- Data definition language โ statements such as CREATE TABLE that define structure.
- Dialect
- A databaseโs flavour of SQL, with its own types, quoting and functions.
- JSONB
- PostgreSQLโs binary JSON type, which can be indexed and queried.
- Quoted identifier
- A table or column name wrapped in backticks, double quotes or brackets so any name is allowed.
Frequently asked questions
Can I convert a single JSON object?
Yes, it becomes one row.
How are nested objects stored?
As JSON text in a JSON/JSONB/TEXT column.
Is the output safe from SQL injection?
Values are escaped for literal use, but for applications always use parameterised queries.
Why is a column TEXT when all my values are short?
It was null or missing in every row, so there was no value to measure, or you chose SQLite, which uses TEXT for all strings.
Does it create indexes or foreign keys?
No. It writes only the table and the rows; add keys, indexes and constraints yourself.
What table name is used if I leave the box empty?
my_table, quoted for the selected database.
Last updated 2026-11-28 ยท Built by Vinayak Agarwal ยท Part of Developer & Web (77 tools)