JSON to SQL INSERT

Generate INSERT statements from JSON records.

Input
JSON input
Output
Result
Options

One statement with all rows, instead of one statement per row.

About this tool


A JSON array of objects converts neatly to INSERT statements, and unlike CSV it arrives with real types already: numbers are numbers, booleans are booleans, and null is genuinely null rather than an empty cell that has to be interpreted.

That makes this the better route when your data comes from an API response or a fixture file, since no type guessing is involved.

How to use it

  1. Paste or upload your jsonDrop a file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input; open Options to change the behaviour.
  3. Generate SQLPress Generate SQL, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Copy or downloadCopy the result, or download it as a .sql file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Records with a null and a nested object

Input

[{"id":1,"name":"Alice","meta":{"role":"admin"}},{"id":2,"name":null}]

Output

INSERT INTO "users" ("id", "name", "meta") VALUES (1, 'Alice', '{"role":"admin"}');
INSERT INTO "users" ("id", "name", "meta") VALUES (2, NULL, NULL);

The nested object becomes JSON text; the missing key and the explicit null both become NULL.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Columns are the union of all keys
Every record is scanned and the full set of keys becomes the column list. A record missing a key gets NULL for that column, so records with differing shapes still produce valid statements with a consistent column list.
JSON types map directly
Numbers are written unquoted, true and false become boolean literals, strings are quoted with their single quotes doubled, and null becomes NULL. No inference is needed, which removes the main source of error in the CSV equivalent.
Nested objects become JSON strings
An object or array value is serialised to JSON text and inserted as a quoted string. That is usually what you want for a JSON or JSONB column in PostgreSQL, or a JSON column in MySQL, but if the target column is a scalar type, flatten the data first.
Escaping and identifier quoting
Single quotes in values are doubled, and identifier quoting follows the selected dialect: double quotes for PostgreSQL, backticks for MySQL, square brackets for SQL Server. Quote characters inside a table or column name are escaped by doubling too.

Limitations


  • Has no access to your schema, so column names and types are not validated.
  • Nested structures become JSON strings rather than related rows.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


How are nested objects handled?
They are serialised as JSON strings, which suits a JSON or JSONB column. Flatten the data first if the target column is a scalar type.
What if my records have different fields?
The column list is the union of all keys, and any record missing a key gets NULL for it.
Why is this better than going via CSV?
JSON already carries types, so nothing has to be inferred. A JSON null is unambiguous, whereas an empty CSV cell could mean null or an empty string.