Skip to content
Devtoolry

JSON to SQL Insert

Convert a JSON array of objects into SQL INSERT statements online for MySQL, PostgreSQL or SQLite. Seed databases and test fixtures in seconds.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON to SQL Insert

The JSON to SQL Insert converter turns a JSON array of objects into INSERT statements for MySQL, PostgreSQL or SQLite, quoting identifiers and escaping values for the dialect you choose.

Conversion happens in your browser, so your files and records stay private.

How to use the JSON to SQL Insert

  1. Paste a JSON array of objects.
  2. Set the table name and dialect, and choose one multi-row INSERT or one per row.
  3. Copy the SQL and run it against your database.

Example

Seed a users table

Input

[
  { "id": 1, "email": "[email protected]", "name": "Ada O'Neil", "active": true, "meta": { "plan": "pro" } },
  { "id": 2, "email": "[email protected]", "name": "Grace", "active": false, "meta": null }
]

Result

INSERT INTO `users` (`id`, `email`, `name`, `active`, `meta`) VALUES
  (1, '[email protected]', 'Ada O''Neil', 1, '{"plan":"pro"}'),
  (2, '[email protected]', 'Grace', 0, NULL);

MySQL dialect: identifiers in backticks, the apostrophe in O’Neil escaped, booleans as 1 and 0, and the meta object stored as JSON text.

Common mistakes

  • Rows with different keys. Columns come from all objects, and missing values are inserted as NULL. Make sure those columns allow NULL or have a default.
  • Very large inserts. One multi-row INSERT can exceed max_allowed_packet in MySQL. Use one INSERT per row, or split the data, for many thousands of rows.
  • Running generated SQL on production. The values are escaped, but review the statements and test on a copy first, especially the table name and the dialect.

Works well with the JSON to SQL Insert

Frequently asked questions

Are values escaped safely?

Yes. Strings are quoted and escaped for the selected dialect, and identifiers are quoted. Still review generated SQL before running it on production data.

How are nested objects stored?

Objects and arrays are written as JSON text, which suits JSON or TEXT columns.

Does it create the table?

No. It writes INSERT statements for an existing table, so you keep control of column types and indexes.

How are booleans written in PostgreSQL?

As TRUE and FALSE. MySQL and SQLite have no real boolean type, so they get 1 and 0.

Guides and tutorials