Skip to content

JSON to SQL Converter

Turn JSON or CSV into CREATE TABLE and INSERT statements. Runs in your browser.

Loading tool…

About this json to sql converter

This converter turns a JSON array or a CSV file into SQL: a CREATE TABLE statement with guessed column types, followed by INSERT statements. It writes the right syntax for MySQL, PostgreSQL, SQLite or SQL Server, so you can seed a database, load test data or move a spreadsheet into a table.

The hard part of hand-written INSERTs is quoting. A name like O'Brien breaks the statement, a backslash means different things in MySQL and PostgreSQL, and each database quotes column names its own way. This tool follows each database's manual: quotes are doubled, identifiers get backticks, double quotes or square brackets as needed, and SQL Server text gets the N'' prefix for Unicode.

Everything runs in your browser, so a customer export never touches a server. If the data needs cleaning first, open it in the CSV editor and come back.

Features

  • Four SQL dialects

    MySQL and MariaDB, PostgreSQL, SQLite and SQL Server, each with its own identifier quoting, boolean literals, JSON column type and CREATE TABLE IF NOT EXISTS form.

  • Column types from your data

    Integers, big integers, decimals, booleans, ISO dates, date-times (with or without a time zone), text and JSON are detected per column. A column is NOT NULL only when every row has a value.

  • JSON or CSV input

    Paste an array of objects, an object that wraps an array, JSON Lines or CSV with a header row. Auto-detect picks the format, or you can set it.

  • Batch INSERTs

    Write one statement per row or group 50 to 1,000 rows per INSERT. Multi-row inserts load much faster, and SQL Server's 1,000-row limit is respected.

  • Nested data handled

    Nested objects and arrays go into a JSON, JSONB or text column as JSON text. Or flatten them into columns such as address_city.

  • Checks before you run it

    Duplicate or empty primary keys, columns that mix numbers and text, and rows missing keys are reported, so the script does not fail halfway through.

How to use the json to sql converter

  1. 1Paste a JSON array or CSV, or open a file.
  2. 2Choose the database, table name, batch size and primary key.
  3. 3Check the column types, then copy or download the .sql script.

When to use it

  • Seeding a development database

    Paste the JSON fixtures your API returns, pick PostgreSQL and run the script in psql. The table and data are ready in one go.

  • Importing a spreadsheet

    Export the sheet as CSV, open it here, choose the primary key and download a .sql file you can run in any client.

  • Moving data between databases

    Export rows as JSON from one system, then generate INSERTs in the other system's dialect without fighting quoting rules.

  • Writing a migration with sample data

    Generate the CREATE TABLE, adjust the types, then run the INSERTs through the SQL formatter to match your house style.

How do you escape a single quote in SQL?

Write it twice. The SQL standard, PostgreSQL, SQLite and SQL Server all read '' inside a string as one quote, so O'Brien is written 'O''Brien'. This tool does that in every dialect.

MySQL adds a second rule. In its default mode a backslash starts an escape sequence, so C:\temp would lose its backslash. The tool doubles backslashes for MySQL. If your server runs with the NO_BACKSLASH_ESCAPES mode, untick that option, because doubled backslashes would then be stored as two characters.

PostgreSQL has treated backslashes as plain characters since version 9.1, when standard_conforming_strings became the default. No E'' strings are needed.

Backticks, double quotes or brackets?

Column and table names that clash with keywords, contain spaces or use mixed case have to be quoted. Each database has its own style:

  • MySQL: `order date`, with backticks. Double quotes only work there when ANSI_QUOTES is on.
  • PostgreSQL: "order date". Unquoted names are folded to lowercase, so CustomerId is quoted to keep its case.
  • SQLite: "order date". It also accepts brackets and backticks for compatibility.
  • SQL Server: [order date]. Double quotes also work while QUOTED_IDENTIFIER is ON, which is the default.

How are column types chosen?

Each column is scanned across all rows. Whole numbers become INTEGER, or BIGINT once a value passes 2,147,483,647. Numbers with decimals become DOUBLE, DOUBLE PRECISION, REAL or FLOAT. true and false become BOOLEAN, or BIT in SQL Server and INTEGER in SQLite. Strings like 2026-03-14 become DATE, and full timestamps become DATETIME, TIMESTAMP or DATETIME2.

Timestamps with a Z or an offset become TIMESTAMPTZ in PostgreSQL and DATETIMEOFFSET in SQL Server, so the zone is kept. MySQL DATETIME has no zone, so the suffix is removed and a note says so. A column that mixes types falls back to text. Check the Column types panel and edit the CREATE TABLE if you know better, for example to use DECIMAL(10,2) for money.

Is a multi-row INSERT faster?

Usually, by a wide margin. Each statement has parsing and round-trip overhead, and one INSERT with 500 rows pays it once. For very large loads, use the database's bulk tool, such as COPY in PostgreSQL or LOAD DATA in MySQL, with a CSV file. Wrapping the script in a transaction also helps, and means a failure leaves the table untouched.

Why use Mavros

 MavrosTypical upload sites
Where your data goesStays in your browserUploaded to a server
Quote escapingPer dialect, including MySQL backslashesOne rule for every database
Identifier quotingBackticks, double quotes or brackets, only when neededAlways one style
Column typesGuessed from every row, with time zonesEverything as VARCHAR(255)
Batch size1 to 1,000 rows per INSERTOne statement per row

Tips

  • Pick a primary key only if the column is unique. The tool warns about duplicates before you find out from the database.
  • Turn on Empty strings as NULL for CSV exports, where a missing value is usually an empty cell rather than real empty text.
  • Very large IDs in JSON can lose precision in JavaScript. Keep them as strings in the source, or check the values after import.
  • Have JSON with odd formatting or comments? Validate it in the JSON formatter first.
  • Need fake rows to test with? Generate them with the fake data generator and paste the JSON here.

Questions

How do I convert JSON to SQL INSERT statements?

Paste a JSON array of objects, pick your database and table name, and copy the script. Keys become columns, and each object becomes one row in an INSERT.

Can it convert CSV to SQL?

Yes. Paste CSV with a header row, or open a .csv file. Numbers and booleans are detected where nothing is lost, so 007 stays text.

How do I escape a single quote in SQL?

Double it: 'O''Brien'. That works in MySQL, PostgreSQL, SQLite and SQL Server. MySQL also accepts \' in its default mode, but doubling is the portable form.

Which databases are supported?

MySQL (and MariaDB), PostgreSQL, SQLite and SQL Server. Each gets its own quoting, types and CREATE TABLE syntax.

How is nested JSON stored?

As JSON text in a JSON column (MySQL), JSONB (PostgreSQL), TEXT (SQLite) or NVARCHAR(MAX) (SQL Server). Turn on flattening to spread nested objects into columns instead.

What happens to missing keys?

Columns are the union of every key in every object. A row without a key gets NULL in that column, and the column is created nullable.

Why do strings in SQL Server start with N?

N'...' marks a Unicode literal for NVARCHAR columns. Without it, characters outside the database's code page, such as ø or Chinese text, can turn into question marks.

Is my data uploaded?

No. Reading the JSON or CSV and writing the SQL happen in your browser. Nothing is stored or sent.