HomeFormattersCodeJSON to SQL INSERT

JSON to SQL INSERT

Code

Convert a JSON array of objects to SQL INSERT statements instantly. Supports MySQL, PostgreSQL, and SQLite dialects. In-browser — data never uploaded.

What is a JSON→SQL?

A JSON to SQL formatter converts structured JSON data — an API response, a log file, an exported dataset — into valid SQL INSERT statements ready to load into a relational database. Instead of manually mapping field names to column names and value by value, you paste the JSON and the formatter does the translation automatically.

JSON and SQL are the two most common data exchange formats in web development. Data frequently lives in one format but needs to be migrated to the other: seeding a development database from a JSON fixture file, importing an API export into a reporting table, or bootstrapping a new service from a legacy JSON dataset. Manually writing INSERT statements for even twenty rows is tedious and error-prone — a single misquoted string or unescaped apostrophe breaks the entire batch.

The formatter handles MySQL, PostgreSQL, and SQLite dialects correctly, applying the right quoting style for identifiers and the right literal format for booleans and null values. It supports both per-row and batch INSERT modes. Use it alongside the JSON Formatter to clean up your source data first, or the CSV to JSON Formatter to convert a CSV export before generating SQL.

How to use this JSON→SQL calculator

  1. Paste your JSON into the JSON Input field. It can be a single object (produces one INSERT) or an array of objects (produces one INSERT per element).
  2. Enter the Table Name — the exact database table you want to insert into.
  3. Select the SQL Dialect: MySQL, PostgreSQL, or SQLite.
  4. Choose the Batch Size setting: "All rows in one statement" for fastest import, or "One statement per row" for granular control.
  5. Review the generated SQL in the output field. Check that column names match your schema and that value types look correct.
  6. Copy and paste into your database client, migration file, or seed script.

Formula & Methodology

The formatter maps JSON value types to SQL literals as follows:

| JSON type | MySQL | PostgreSQL | SQLite |
|---|---|---|---|
| String | 'value' (single-quoted) | 'value' | 'value' |
| Integer | 42 | 42 | 42 |
| Decimal | 3.14 | 3.14 | 3.14 |
| Boolean true | 1 | TRUE | 1 |
| Boolean false | 0 | FALSE | 0 |
| null | NULL | NULL | NULL |
| Object/Array | '{"key":"val"}' | '{"key":"val"}' | '{"key":"val"}' |

Single quotes inside string values are escaped by doubling them ('''), which is the standard SQL escaping mechanism.

Before/after example:

Input JSON:
json [{"id": 1, "name": "Alice", "active": true}, {"id": 2, "name": "Bob's", "active": false}] 

Generated SQL (PostgreSQL, per-row):
sql INSERT INTO "users" ("id", "name", "active") VALUES (1, 'Alice', TRUE); INSERT INTO "users" ("id", "name", "active") VALUES (2, 'Bob''s', FALSE); 

Frequently Asked Questions

A JSON to SQL formatter converts a JSON object or array of objects into SQL INSERT statements. It reads the field names as column names and the values as data to insert, generating valid SQL for MySQL, PostgreSQL, or SQLite. This saves the manual work of writing INSERT statements row by row.
The formatter supports MySQL (backtick-quoted identifiers), PostgreSQL (double-quoted identifiers, TRUE/FALSE booleans), and SQLite (double-quoted identifiers). Choose the dialect that matches your database to get correctly formatted output.
Yes. Paste a JSON array and each element becomes a separate INSERT row. Use the 'Batch all rows' option to generate a single multi-row INSERT statement, which is faster for bulk imports. Use 'One per row' for individual INSERT statements that can be run selectively.
Strings are single-quoted with internal single quotes escaped as two single quotes. Numbers are inserted as-is. Booleans become TRUE/FALSE in PostgreSQL and 1/0 in MySQL and SQLite. Null values become NULL. Nested objects and arrays are serialised to their JSON string representation.
Enter the exact name of the target database table. The formatter uses this name as-is in the INSERT INTO statement. If your table name contains special characters or reserved words, the dialect's quoting style (backtick for MySQL, double-quote for PostgreSQL/SQLite) is applied automatically.
There is no hard limit — the formatter processes the entire JSON array you paste. However, very large datasets (thousands of rows) may be slow in the browser. For large imports, consider splitting the JSON into chunks or using a dedicated ETL tool.
Yes. The input is parsed with JSON.parse() first. If the JSON is invalid, the output shows a parse error instead of broken SQL. Use the [JSON Formatter](/json-formatter/) to fix any syntax issues before converting.
The per-row mode generates one INSERT statement per JSON object, each ending with a semicolon. The batch mode generates a single INSERT with multiple value tuples separated by commas — this is significantly faster for large imports because the database processes one statement rather than thousands.
No. All conversion happens in your browser. Your JSON data never leaves your device and is not transmitted to any server. This makes the tool safe for data containing sensitive fields.
Yes. The generated SQL is valid and ready to paste into a .sql migration file or run in a database client. Always review the output before running it against a production database, especially to confirm column names match your schema.
Nested objects and arrays are converted to their JSON string representation and inserted as a quoted string. This is appropriate for JSON/JSONB columns in PostgreSQL. If you want nested data normalised into separate tables, you will need to restructure the JSON first.
Also known as
JSON to SQLJSON to INSERTconvert JSON to SQLgenerate SQL from JSONJSON array to SQL