Tools / JSON ↔ SQL Converter

JSON ↔ SQL Converter.

Turn a JSON array into CREATE TABLE and INSERT statements, or read INSERT statements back into JSON.

Runs in your browser

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result
Result
Stats

About JSON ↔ SQL Converter

The JSON ↔ SQL Converter turns an array of JSON objects into SQL you can run, and turns INSERT statements from a dump back into JSON. Every distinct key becomes a column, in the order it first appears, and missing keys become NULL. Column types are inferred from the values: whole numbers become INT or BIGINT, decimals become DOUBLE or REAL, booleans become BOOLEAN or BIT, ISO dates and timestamps get date types, and nested objects or arrays are stored as JSON text in a JSON, JSONB or NVARCHAR(MAX) column. Identifiers and strings are quoted for the dialect you choose: backticks for MySQL, double quotes for PostgreSQL and SQLite, brackets for SQL Server, with apostrophes doubled and backslashes escaped where MySQL needs it. For example [{"id": 1, "name": "O'Hara"}] becomes INSERT INTO "users" ("id", "name") VALUES (1, 'O''Hara'). Multi-row INSERTs are grouped in batches of 500 rows (1,000 for SQL Server, its limit). In the other direction the reader understands INSERT … VALUES with or without a column list, several rows per statement, comments, escaped quotes, NULL, TRUE and FALSE; when the column list is missing it borrows the names from a CREATE TABLE in the same input. Expressions such as NOW() are kept as text, and INSERT … SELECT is reported as an error because the rows are not in the file. Nothing is uploaded: the conversion runs in your browser.

How to Use

  1. Paste a JSON array or SQL INSERT statements and choose the direction.
  2. Set the table name and dialect, and decide whether to add CREATE TABLE.
  3. Copy the SQL or JSON, or download it.

Frequently Asked Questions

How are nested objects stored?

As JSON text. The column type is JSON in MySQL, JSONB in PostgreSQL, TEXT in SQLite and NVARCHAR(MAX) in SQL Server.

Can it read a mysqldump file?

Yes, as long as the data is in INSERT … VALUES statements. Other statements are skipped and counted in the stats, and CREATE TABLE is used to name columns when INSERTs have no column list.

Are the generated types final?

They are a starting point inferred from the sample. Review lengths, keys and NOT NULL constraints before using the schema in production.

Is my data private?

Yes. The tool runs in your browser and makes no network requests with your data.

Related Tools