Ttooleras
🗃️

JSON to SQL

Converters

Generate SQL INSERT statements and CREATE TABLE from JSON arrays. Free, private — all processing in your browser.

The JSON to SQL Converter transforms JSON arrays into CREATE TABLE and INSERT INTO statements for your database. Paste an array of JSON objects, pick your database dialect (MySQL, PostgreSQL, SQL Server, SQLite, Oracle, MariaDB), and get ready-to-run SQL. The tool infers column types from the first few records (VARCHAR for strings, INT for integers, DECIMAL for floats, BOOLEAN for true/false, TIMESTAMP for dates), properly escapes string values (preventing SQL injection in literal data), and handles NULL values correctly. Supports nested objects (flattened with dot notation or stored as JSON columns for Postgres JSONB/MySQL JSON).

Converting JSON to SQL is a common task: importing API data into a database, migrating from NoSQL to relational, loading JSON dumps into analytics databases, or bulk-seeding test data. Doing this by hand for hundreds of rows is tedious and error-prone (missing quotes, SQL injection in string values). This tool automates the whole process — proper escaping, correct types, batched INSERTs for performance. All processing runs in your browser, so your JSON (which may contain customer data, financial records, or proprietary info) never uploads.

How to use the JSON to SQL

  1. 1

    Paste JSON array

    Array of objects where each object is a row. Can be an API response, export file, or generated data.

  2. 2

    Select database

    MySQL, PostgreSQL, SQL Server, SQLite, Oracle, MariaDB — dialect matters for syntax and types.

  3. 3

    Set table name

    Table to insert into. Must exist or use CREATE TABLE statement generated.

  4. 4

    Configure nested object handling

    Flatten (dot notation), JSON column, or split into related tables.

  5. 5

    Generate

    CREATE TABLE and INSERT statements appear. Review column types, values.

  6. 6

    Copy to SQL client

    Paste into your database client (DBeaver, pgAdmin, MySQL Workbench) or ORM script.

Worked examples

Simple users table

Flat objects.

Input
[
  {"id": 1, "name": "Alice", "age": 30},
  {"id": 2, "name": "Bob", "age": 25}
]
Output
CREATE TABLE users (
  id INT,
  name VARCHAR(255),
  age INT
);

INSERT INTO users (id, name, age) VALUES
  (1, 'Alice', 30),
  (2, 'Bob', 25);

Handling NULLs

Missing or null values.

Input
[
  {"id": 1, "email": "a@x.com"},
  {"id": 2, "email": null}
]
Output
CREATE TABLE users (
  id INT,
  email VARCHAR(255)
);

INSERT INTO users (id, email) VALUES
  (1, 'a@x.com'),
  (2, NULL);

Escaped strings

Single quotes doubled.

Input
[{"name": "O Brien, John"}]
Output
INSERT INTO users (name) VALUES ('O Brien, John');

Nested as JSONB (Postgres)

Nested object stored as JSONB.

Input
[{
  "id": 1,
  "metadata": {"tags": ["a", "b"]}
}]
Output
CREATE TABLE items (
  id INTEGER,
  metadata JSONB
);

INSERT INTO items (id, metadata) VALUES
  (1, '{"tags":["a","b"]}'::jsonb);

Nested flattened

Dot notation for nested fields.

Input
[{
  "id": 1,
  "user": {"name": "Alice", "age": 30}
}]
Output
CREATE TABLE items (
  id INT,
  user_name VARCHAR(255),
  user_age INT
);

INSERT INTO items (id, user_name, user_age) VALUES
  (1, 'Alice', 30);

MySQL with backticks

Identifier quoting.

Input
[{"order": 1, "group": "A"}]
Output
CREATE TABLE `items` (
  `order` INT,
  `group` VARCHAR(255)
);

INSERT INTO `items` (`order`, `group`) VALUES
  (1, 'A');

-- Note: backticks required because "order" and "group" are SQL keywords

Features at a glance

6 database dialects

MySQL, PostgreSQL, SQL Server, SQLite, Oracle, MariaDB — dialect-specific syntax.

Type inference

Analyzes JSON to pick appropriate column types (INT vs BIGINT, VARCHAR vs TEXT, etc.).

Safe string escaping

Single quotes doubled. Prevents SQL injection via literal data.

NULL handling

JSON null and missing fields become SQL NULL correctly.

Nested object strategies

Flatten with dot notation, store as JSONB/JSON, or split into related tables.

Batched INSERT

Multi-row INSERTs for performance. Configurable batch size.

Table name control

Use default or specify custom table name.

100% client-side

Your JSON (customer data, financial records) stays in browser.

When to use the JSON to SQL

Data migration

  • NoSQL to SQL: Export MongoDB/Firestore JSON, convert to SQL, import into Postgres/MySQL.
  • API response to database: Cache external API data in your database — convert JSON responses to INSERT statements.
  • CSV through JSON to SQL: CSV → JSON (with our CSV to JSON) → SQL for complex data pipelines.
  • System consolidation: Migrate data from old system (JSON export) to new system (SQL database).

Development

  • Seed test data: Generate SQL for dev/staging databases from realistic JSON samples.
  • Prototype backends: Quick local database for prototyping APIs. Populate from JSON fixtures.
  • Demo data: Create demo databases with sample JSON data.
  • Unit test fixtures: Database-level test fixtures from JSON mock data.

Analytics

  • Load JSON logs: Structured logs (JSON lines) converted to SQL for analytics in BigQuery, Redshift, Snowflake.
  • Data warehouse loading: ETL pipeline final step — JSON to bulk INSERT.
  • Ad-hoc analysis: JSON API data loaded to analyze with SQL queries.

How it works

SQL generation from JSON:

Input format:

Array of objects (each object becomes a row):

``json
[
{"id": 1, "name": "Alice", "age": 30},
{"id": 2, "name": "Bob", "age": 25}
]
``

Output CREATE TABLE:

``sql
CREATE TABLE users (
id INT,
name VARCHAR(255),
age INT
);
``

Output INSERT:

``sql
INSERT INTO users (id, name, age) VALUES
(1, 'Alice', 30),
(2, 'Bob', 25);
``

Type inference:

Tool analyzes values across all records to determine column types:

| JSON value | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|
| Integer | INT | INTEGER | INT |
| Large integer | BIGINT | BIGINT | BIGINT |
| Float | DECIMAL(10,2) | NUMERIC | DECIMAL |
| String | VARCHAR(255) | VARCHAR(255) | NVARCHAR(255) |
| Long string | TEXT | TEXT | NTEXT |
| Boolean | BOOLEAN or TINYINT | BOOLEAN | BIT |
| Date string | DATE | DATE | DATE |
| Datetime | DATETIME | TIMESTAMP | DATETIME |
| null | NULLable type | NULLable type | NULLable type |
| Nested object | JSON | JSONB | NVARCHAR(MAX) |

String escaping:

Single quotes doubled: O'BrienO''Brien. Not backslash escaping (varies by dialect).

NULL handling:

JSON null → SQL NULL (not string 'null').
Missing field → NULL.

Batched INSERTs:

Multi-row INSERT performs better than individual statements:

```sql
-- GOOD (single round trip)
INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Carol');

-- SLOWER (multiple round trips)
INSERT INTO users VALUES (1, 'Alice');
INSERT INTO users VALUES (2, 'Bob');
INSERT INTO users VALUES (3, 'Carol');
```

Tool defaults to batched. Split into smaller batches if INSERT gets too long (MySQL max_allowed_packet, PostgreSQL 1GB limit).

Dialect differences:

MySQL/MariaDB:
- VARCHAR(255) for strings.
- Backticks for identifiers: CREATE TABLE \users\`.
-
INT UNSIGNED` for non-negative.

PostgreSQL:
- VARCHAR or TEXT (no length required).
- Double quotes for identifiers: "users".
- SERIAL for auto-increment columns.
- JSONB for nested objects (indexable, fast).

SQL Server:
- NVARCHAR(255) for Unicode strings.
- Brackets for identifiers: [users].
- BIT for boolean.

SQLite:
- Dynamic typing — declared types are hints.
- INTEGER for auto-increment rowid.

Oracle:
- VARCHAR2 instead of VARCHAR.
- Different datetime types.

Nested object handling:

Three strategies for nested JSON:

1. Flatten with dot notation: {user: {name: "Alice"}} → column user_name.
2. Store as JSON: PostgreSQL JSONB, MySQL JSON, SQL Server NVARCHAR(MAX) with JSON functions.
3. Split into related tables: nested array becomes child table with foreign key (relational normalization).

Tool offers all three; #2 is most common for modern databases.

Common issues:

- Column name with SQL keyword: order, group, select are keywords. Quote them with dialect-specific escape.
- Value too long for VARCHAR(255): tool checks and promotes to TEXT if needed.
- Integer overflow: INT max is 2^31-1. Use BIGINT for larger.
- Date formats: JSON dates are strings. SQL TIMESTAMP/DATE expected format varies by dialect.

Troubleshooting

SQL injection via data

Tool escapes quotes, but if data comes from untrusted source, validate independently. Never trust external JSON — use prepared statements in production, not hand-concatenated SQL.

VARCHAR(255) too short

If a string value exceeds 255 chars, INSERT fails. Tool analyzes max length and picks TEXT when needed. Verify for edge cases.

Integer overflow

MySQL INT max is 2^31 - 1 (about 2.1 billion). Larger integers need BIGINT. Tool checks and picks BIGINT when needed.

Column name is SQL keyword

`order`, `group`, `select`, etc. are keywords. Quote them — MySQL backticks, PostgreSQL double quotes, SQL Server brackets. Tool handles this.

Date format mismatch

SQL TIMESTAMP expects YYYY-MM-DD HH:MM:SS. JSON date strings vary. Tool assumes ISO 8601 (2026-05-05T10:30:00Z). Other formats may need manual conversion.

Nested objects in strict SQL

Old MySQL (pre-5.7), SQLite — no native JSON type. Strategies: (1) JSON as TEXT column. (2) Flatten to multiple columns. (3) Related tables. Pick based on query patterns.

Very large INSERT fails

Databases limit single statement size (MySQL max_allowed_packet, PostgreSQL 1GB). For huge data, batch into multiple INSERTs (tool does this automatically).

Case-sensitive identifiers

MySQL table names are case-sensitive on Linux, not Windows. PostgreSQL is case-sensitive for double-quoted identifiers. Stick to lowercase_with_underscores convention.

JSON to SQL — comparisons and alternatives

JSON to SQL vs JSON to CSV: CSV is flat (no types). SQL has types and can express NULL vs empty string. For databases, SQL is better — preserves types, handles constraints.

This tool vs CSV to SQL: CSV to SQL is simpler (CSV is already flat). JSON has nested structures requiring flattening or JSON column handling.

JSON to INSERT vs JSON import commands: Postgres COPY FROM, MySQL LOAD DATA INFILE, SQL Server BULK INSERT — faster than INSERT for huge data but require specific file formats. For smaller data, INSERT is simpler.

JSON to SQL vs ORM migrations: ORM migrations (Rails migrations, Django models, Prisma schema) are for schema management. This tool for data insertion. Use ORM for ongoing structure; this tool for one-time data loads.

Relational vs JSONB storage: Relational (flattened columns) supports fast querying and indexes. JSONB (Postgres) stores JSON as-is with query operators. Trade-off: relational is optimized, JSONB is flexible.

SQL dialects comparison: MySQL/MariaDB use backticks. PostgreSQL uses double quotes. SQL Server uses brackets. Oracle uses double quotes. SQLite is mostly MySQL-compatible. Each has quirks in types and syntax.

Questions and answers

How does JSON to SQL conversion work?

Tool analyzes JSON array to infer column structure and types. Generates CREATE TABLE (optional) and INSERT INTO statements. Properly escapes strings, handles NULL, and picks appropriate types based on JSON values.

Which database dialects are supported?

MySQL, PostgreSQL, SQL Server, SQLite, Oracle, MariaDB. Each has dialect-specific identifier quoting, type names, and syntax. Pick the right one for your target database.

Is my JSON data safe?

Yes. Conversion happens in your browser. JSON never uploads. Safe for customer data, financial records, proprietary data.

How does it handle nested objects?

Three options: (1) Flatten with dot notation — user.name becomes user_name column. (2) JSON column — stored as JSONB (Postgres), JSON (MySQL 5.7+), NVARCHAR (SQL Server). (3) Related tables — nested arrays become child table. Choose based on query needs.

Does it protect against SQL injection?

Single quotes are doubled ('O Brien' becomes 'O''Brien'). This prevents SQL injection in hand-concatenated queries. But for production, use parameterized queries (prepared statements), not hand-generated SQL. This tool is for data migration and development, not for accepting user input.

Can it handle large JSON files?

Yes, up to browser memory. Tens of thousands of records work fine. For huge datasets (millions of records), use streaming tools or batch imports.

What about dates?

JSON dates are strings. Tool detects ISO 8601 format (2026-05-05) and uses DATE/TIMESTAMP type. Non-ISO formats treated as VARCHAR. Convert to ISO before converting if you want DATE column.

What if I just want INSERT without CREATE TABLE?

Option to skip CREATE TABLE — only generate INSERT statements. Useful when table already exists with your schema.

Can I specify column types manually?

Tool infers types from JSON. For explicit types, edit the CREATE TABLE after generation or provide a type mapping.

Does it work with SQL keywords as column names?

Yes. Tool detects keywords (order, group, user, etc.) and quotes them appropriately for each dialect (backticks for MySQL, double quotes for PostgreSQL, brackets for SQL Server).

Additional resources

Related tools

All Converters

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →