About this tool
Need to load JSON into a database for a quick analysis, a seed script or a test fixture? Paste an array of JSON objects and this tool writes the SQL: a CREATE TABLE with sensible column types and INSERT statements for every record, in the dialect of your database.
How it works
- Each object is a row, and each key is a column. Keys missing from some objects become
NULLin those rows. A single object is treated as one row, and{"users": [...]}uses the array inside. - Column types are inferred from all values: whole numbers become
INTEGER(orBIGINTwhen they exceed 32 bits), decimalsNUMERIC/DOUBLE, true/falseBOOLEAN(BITin SQL Server,0/1in SQLite), ISO datesDATEand timestampsTIMESTAMPTZ/DATETIME, and everything else text. - Columns that are never null get
NOT NULL, and anidcolumn becomes the primary key. - Nested objects and arrays are stored as JSON (
JSONBin PostgreSQL,JSONin MySQL, text elsewhere), or flattened into columns likeaddress_city.
Safe quoting for each database
Identifiers are quoted the way each database expects ("name" in PostgreSQL and SQLite, `name` in MySQL, [name] in SQL Server), so reserved words like order or user work as column names. Single quotes in strings are doubled (O''Brien); MySQL also gets backslashes escaped, and SQL Server gets N'…' for non-ASCII text. MySQL DATETIME has no time zone, so ISO timestamps are written in its YYYY-MM-DD HH:MM:SS format.
Batched inserts
Multi-row INSERT … VALUES (…), (…) statements load much faster than one statement per row. 100–1,000 rows per statement is a good range; SQL Server allows at most 1,000 rows per VALUES list. Choose 1 row per statement when you want to see exactly which row fails. Wrap in a transaction makes the import all-or-nothing.
For big or recurring imports
For millions of rows, use the database’s bulk loader instead: COPY in PostgreSQL, LOAD DATA in MySQL, or .import in SQLite, typically from CSV (JSON to CSV converts the data). PostgreSQL and MySQL can also query JSON directly with jsonb_to_recordset and JSON_TABLE. Check the generated types before using them in production; to tidy the SQL, run it through the SQL formatter.
FAQ
How do I convert JSON to SQL INSERT statements?
Paste an array of JSON objects, set the table name and choose your database. You get a CREATE TABLE statement (optional) and INSERT statements for every object.
Which databases are supported?
PostgreSQL, MySQL and MariaDB, SQLite, and SQL Server. Each gets its own identifier quoting, string escaping, boolean values and column types.
How are nested JSON objects handled?
By default they are stored in a JSON column (JSONB in PostgreSQL, JSON in MySQL). You can flatten them into separate columns such as address_city instead.
What if objects have different keys?
All keys across all objects become columns, and rows without a key get NULL for that column.
Are the generated statements safe from SQL injection?
Values are quoted and escaped for the chosen database, so quotes in your data cannot break out of the string. Still review generated SQL before running it on production data.
Can I insert many rows at once?
Yes. Choose rows per INSERT to generate multi-row statements, which are much faster than one statement per row.