JSON to SQL Converter

Convert JSON arrays to SQL INSERT statements in seconds. Paste any JSON and get ready-to-run SQL for MySQL, PostgreSQL, SQLite, or SQL Server. Free, no signup, works entirely in your browser.

Why Convert JSON to SQL?

JSON has become the universal format for data exchange between APIs, services, and applications. SQL remains the dominant language for storing and querying structured data in relational databases. These two worlds collide constantly in modern development, and bridging the gap between them is a daily task for developers, data engineers, and database administrators.

The most common scenarios where you need to convert JSON to SQL include:

Writing these INSERT statements by hand is tedious and error-prone, especially for large datasets with many columns. Our converter automates the entire process in one click.

How SQL INSERT Statements Are Generated

The converter takes a JSON array where each element is an object representing one database row. It reads the keys from the first object to determine the column names, then iterates through every object to produce the VALUES rows.

Input JSON:

[
  { "id": 1, "name": "Alice", "email": "alice@example.com", "active": true },
  { "id": 2, "name": "Bob",   "email": "bob@example.com",   "active": false },
  { "id": 3, "name": "Carol", "email": "carol@example.com", "active": true }
]

Generated SQL:

INSERT INTO table_name (id, name, email, active) VALUES
(1, 'Alice', 'alice@example.com', TRUE),
(2, 'Bob', 'bob@example.com', FALSE),
(3, 'Carol', 'carol@example.com', TRUE);

The type mapping is automatic: JSON strings become single-quoted SQL strings, numbers stay unquoted, booleans become TRUE/FALSE, and null becomes SQL NULL.

MySQL vs PostgreSQL: Key Differences

While both databases accept standard INSERT syntax, there are subtle differences to be aware of when importing JSON-derived data:

Feature MySQL PostgreSQL
Boolean values 1 / 0 or TRUE / FALSE TRUE / FALSE
JSON column type JSON (since 5.7) JSON or JSONB
Upsert syntax INSERT ... ON DUPLICATE KEY UPDATE INSERT ... ON CONFLICT DO UPDATE
String quoting Single or double quotes Single quotes only
Backtick identifiers Supported Use double quotes instead

Our converter generates standard ANSI SQL that is compatible with both databases, using single-quoted strings and TRUE/FALSE for booleans. For MySQL-specific backtick quoting or PostgreSQL JSONB casting, you may need minor adjustments to the output.

Common Use Cases: Data Migration and Database Seeding

Data migration is one of the most frequent reasons developers need JSON-to-SQL conversion. When a project moves from a document database like MongoDB to PostgreSQL, or when integrating an external API data feed into an internal reporting database, the data typically arrives as JSON and needs to be loaded into SQL tables.

Database seeding is another major use case. Development and staging environments need realistic test data. Teams often store seed data in JSON files in version control because JSON is human-readable and easy to edit. Converting these JSON fixtures to SQL INSERT statements lets you seed any relational database without writing custom scripts.

A typical seed workflow looks like this:

  1. Store your seed data as a JSON array in seeds/users.json
  2. Paste the JSON into the converter to get the INSERT statements
  3. Save the output as seeds/users.sql
  4. Run psql mydb < seeds/users.sql or equivalent

This approach keeps your seed data in a readable format, avoids ORM-specific migration scripts, and makes the data portable across any SQL database engine.

Frequently Asked Questions

How do I convert JSON to SQL INSERT statements?

Paste your JSON array into the converter tool. Each object in the array becomes one INSERT row. The tool reads the keys as column names and the values as row data, generating a complete INSERT INTO statement you can run directly in your database.

Does the JSON to SQL converter work with MySQL and PostgreSQL?

Yes. The generated INSERT statements use standard SQL syntax compatible with MySQL, PostgreSQL, SQLite, and most other relational databases. The converter uses single-quoted strings and TRUE/FALSE booleans, which are valid in all major SQL dialects.

What happens to nested JSON objects when converting to SQL?

Nested objects and arrays are serialized as JSON strings in the SQL output. Modern databases like PostgreSQL (JSONB) and MySQL (JSON column type) can store and query these values natively. Alternatively, you can flatten nested structures into separate columns before converting.

Can I convert a large JSON file with thousands of records to SQL?

Yes. The converter handles large arrays and generates batched multi-row INSERT statements for better performance. Batched inserts are significantly faster than individual single-row inserts when loading large datasets into a database.

Convert Your JSON to SQL Now

Free, instant, 100% private. No account needed.

JSON to SQL Conversion Example

Converting JSON arrays to SQL INSERT statements is a common data migration task. Each JSON object becomes a row, and each key becomes a column.

JSON Array → SQL Statements

// JSON Input
[
  {"id": 1, "name": "Alice", "email": "alice@example.com", "active": true},
  {"id": 2, "name": "Bob",   "email": "bob@example.com",   "active": false}
]

-- SQL Output
CREATE TABLE users (
  id      INT NOT NULL,
  name    VARCHAR(255),
  email   VARCHAR(255),
  active  BOOLEAN
);

INSERT INTO users (id, name, email, active) VALUES
  (1, 'Alice', 'alice@example.com', TRUE),
  (2, 'Bob',   'bob@example.com',   FALSE);

JSON to SQL Type Mappings

JSON TypeSQL TypeNotes
stringVARCHAR(255)VARCHAR(MAX) for SQL Server
integerINTBIGINT for large numbers
floatDECIMAL(10,2)or FLOAT / DOUBLE
booleanBOOLEANTINYINT(1) for MySQL
nullNULLColumn should be nullable
arrayJSON / TEXTStore as JSON string
objectJSON / TEXTStore as JSON string
date stringDATE / DATETIMEParse and format correctly

Bulk Insert Optimization

-- MySQL: multi-row INSERT (fastest)
INSERT INTO users (id, name) VALUES
  (1, 'Alice'),
  (2, 'Bob'),
  (3, 'Carol');

-- PostgreSQL: COPY for large datasets
COPY users (id, name, email) FROM STDIN (FORMAT csv);

-- SQLite: use transactions for speed
BEGIN TRANSACTION;
INSERT INTO users VALUES (1, 'Alice');
INSERT INTO users VALUES (2, 'Bob');
COMMIT;

Also useful: JWT Decoder | JSON Validator | JSON Formatter | JSON to Excel | JSON to GraphQL

JSON to SQL Conversion: How It Works

The converter analyses the keys of the first JSON object to infer column names and SQL types, then generates a CREATE TABLE statement followed by an INSERT statement for each row. The example below shows a typical input array and the generated SQL output.

// Input JSON array
[
  {"id": 1, "name": "Alice", "email": "alice@example.com", "active": true},
  {"id": 2, "name": "Bob",   "email": "bob@example.com",   "active": false},
  {"id": 3, "name": "Carol", "email": "carol@example.com", "active": true}
]
-- Generated SQL INSERT statements
CREATE TABLE IF NOT EXISTS json_data (
  id INTEGER,
  name VARCHAR(255),
  email VARCHAR(255),
  active BOOLEAN
);

INSERT INTO json_data (id, name, email, active) VALUES (1, 'Alice', 'alice@example.com', TRUE);
INSERT INTO json_data (id, name, email, active) VALUES (2, 'Bob', 'bob@example.com', FALSE);
INSERT INTO json_data (id, name, email, active) VALUES (3, 'Carol', 'carol@example.com', TRUE);

JSON Type to SQL Type Mapping

Different database engines use different type names for the same concept. The table below shows how each JSON value type maps across the four most widely-used SQL databases. For nested objects and arrays, all databases either use a native JSON column type or fall back to a text column.

JSON Type PostgreSQL MySQL SQLite SQL Server
stringVARCHAR/TEXTVARCHAR/TEXTTEXTNVARCHAR
integerINTEGER/BIGINTINT/BIGINTINTEGERINT/BIGINT
floatNUMERIC/DECIMALDECIMALREALDECIMAL
booleanBOOLEANTINYINT(1)INTEGERBIT
nullNULLNULLNULLNULL
arrayJSONBJSONTEXTNVARCHAR(MAX)
objectJSONBJSONTEXTNVARCHAR(MAX)