Skip to content
gohacks.dev
Databases

JSON or CSV to SQL INSERT

Turn a JSON array or a CSV file into multi-row INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server, batched, with optional upsert.

Free · No sign-up · Your inputs stay in your browser

Input

Generate SQL INSERT statements from JSON or CSV

Output

SQL

2 rows, 5 columns, 1 statement

Values are written as literals with quotes doubled, so the output is safe to run as a one-off script. Application code should use bound parameters; Laravel's DB::table()->insert() and upsert() do it for you.

Runs in this browser. Nothing you paste is sent to a server.

Batching

One multi-row INSERT is much faster than the same rows inserted one by one, because each statement costs a round trip and a commit when autocommit is on. Very large statements hit limits instead: MySQL rejects a packet larger than max_allowed_packet, 64 MiB by default in MySQL 8.0 and later. A few hundred to a few thousand rows per statement is a safe range.

Upserts differ by database

MySQL's ON DUPLICATE KEY UPDATE fires on any unique index; PostgreSQL and SQLite's ON CONFLICT (column) names the constraint to check. Laravel's upsert() hides the difference, and needs a unique index on the columns you pass, or every row is inserted.

Share

Frequently asked questions

How are NULLs and booleans written?
Missing keys and JSON null become NULL. Booleans become TRUE or FALSE for PostgreSQL and 1 or 0 for MySQL, SQLite and SQL Server.
Is the output safe to run?
Values are written as properly escaped literals, so it is safe as a one-off script. In application code, use bound parameters instead.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools