JSON to SQL

Generate CREATE TABLE and INSERT statements from JSON rows.

Runs in your browser Instant No sign-up
Dialect
JSON array
SQL

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How it works

Paste a JSON array of objects (or a single object for one row). Each object is a row, and the columns are every key that appears in any object, in the order they first appear. A key that is missing from a row is inserted as NULL.

  1. Table — the table name, optionally schema-qualified (sales.orders). It must be a plain identifier: letters, digits and underscores, not starting with a digit.
  2. Dialect — PostgreSQL, MySQL, SQLite or SQL Server. This decides identifier quoting, string escaping, boolean literals and type names.
  3. CREATE TABLE — include a CREATE TABLE statement with inferred column types.
  4. One INSERT per row — off: multi-row INSERT … VALUES (…), (…) statements, split by Rows per INSERT (under More options; SQL Server accepts at most 1,000 rows per VALUES list). On: one statement per row, which is slower to load but easier to diff or run selectively.

Example

[
  { "id": 1, "name": "Ada Lovelace", "email": "ada@example.com", "balance": 1250.5, "active": true, "tags": ["admin"] },
  { "id": 2, "name": "Linh O'Brien", "email": "linh@example.com", "balance": -20, "active": false, "tags": [] },
  { "id": 3, "name": "Grace Hopper", "email": null, "balance": 0, "active": true }
]

PostgreSQL output:

CREATE TABLE "my_table" (
  "id"      INTEGER,
  "name"    TEXT,
  "email"   TEXT,
  "balance" NUMERIC,
  "active"  BOOLEAN,
  "tags"    JSONB
);

INSERT INTO "my_table" ("id", "name", "email", "balance", "active", "tags") VALUES
  (1, 'Ada Lovelace', 'ada@example.com', 1250.5, TRUE, '["admin"]'),
  (2, 'Linh O''Brien', 'linh@example.com', -20, FALSE, '[]'),
  (3, 'Grace Hopper', NULL, 0, TRUE, NULL);

With MySQL selected, balance becomes DECIMAL(10, 1) (the scale is the most decimal places seen, the precision at least 10), id becomes INT and tags becomes JSON.

Column types by dialect

JSON values in the column PostgreSQL MySQL SQLite SQL Server
Whole numbers within 32 bits INTEGER INT INTEGER INT
Whole numbers within 64 bits BIGINT BIGINT INTEGER BIGINT
Decimals, or integers beyond 64 bits NUMERIC DECIMAL(p, s) NUMERIC DECIMAL(p, s)
Numbers with an exponent (6.02e23) DOUBLE PRECISION DOUBLE REAL FLOAT
true / false BOOLEAN BOOLEAN BOOLEAN (stored as 1/0) BIT (1/0)
Strings, mixed kinds, or only nulls TEXT TEXT (LONGTEXT for long strings) TEXT NVARCHAR(MAX)
Objects or arrays JSONB JSON TEXT NVARCHAR(MAX)

Dates stay text: "2026-09-30T10:15:00Z" is inserted into a TEXT column. Change the column to TIMESTAMPTZ, DATETIME or DATETIME2 by hand if you need date arithmetic, and check that your server accepts the string format (MySQL, for example, does not accept the trailing Z).

How strings are escaped

The value C:\Users\ada, It's "fine" and 1'; DROP TABLE users; -- in each dialect:

-- PostgreSQL: E'' string when there is a backslash, so it works whatever standard_conforming_strings is set to
(E'C:\\Users\\ada', 'It''s "fine"', '1''; DROP TABLE users; --')
-- MySQL: backslashes doubled (default sql_mode), quotes doubled
('C:\\Users\\ada', 'It''s "fine"', '1''; DROP TABLE users; --')
-- SQLite: only quotes are doubled; backslash is an ordinary character
('C:\Users\ada', 'It''s "fine"', '1''; DROP TABLE users; --')
-- SQL Server: N'' Unicode literals, quotes doubled
(N'C:\Users\ada', N'It''s "fine"', N'1''; DROP TABLE users; --')

Single quotes are always doubled rather than written as \', so a MySQL server running with NO_BACKSLASH_ESCAPES still reads every literal as closed in the right place (backslashes would then be doubled in the stored value). In T-SQL, a backslash directly before a line break is a line continuation that removes both, so the converter ends the literal before the line break and joins the parts with +. PostgreSQL text cannot hold NUL characters, and most SQLite and SQL Server tools treat NUL as the end of the statement, so NULs are removed with a warning (MySQL keeps them as \0).

Common problems

  • “Item 2 is a number. Expected an array of objects…” — every element must be an object. Wrap scalar lists first, e.g. [{"value": 1}, {"value": 2}].
  • A mixed-type warning such as Column "code" mixes number and text values, so it is TEXT and every value is quoted. — the column held both 42 and "A-7". That is usually right for codes; fix the source data if it should be numeric.
  • Columns that differ only in case (Id and id) — MySQL, SQLite and SQL Server treat column names case-insensitively, so CREATE TABLE fails. Rename one key.
  • Invalid JSON — the error shows the line and column. Fix it with JSON Repair or check it in the JSON Validator.

To reformat the result (keyword case, indentation), paste it into the SQL Formatter. For spreadsheet tools rather than a database, JSON to CSV produces a file Excel opens directly.

Frequently asked questions

Is the generated SQL safe against injection?

Values are always written as escaped literals for the chosen dialect, and identifiers are always quoted, so a value such as 1'; DROP TABLE users; -- stays a plain string. The escaping follows each server's rules, including PostgreSQL's E'' strings for backslashes and SQL Server's backslash line continuation. For data that arrives at runtime in an application, use parameterised queries rather than generated SQL text.

How are column types chosen?

From every non-null value in the column. Whole numbers become INTEGER (or INT), or BIGINT beyond 32 bits; decimals become NUMERIC or DECIMAL(p, s); numbers written with an exponent become a floating-point type; true/false become BOOLEAN (BIT in SQL Server); objects and arrays become JSONB, JSON or text. A column that mixes kinds, such as numbers and strings, becomes TEXT with a warning.

What happens to nested objects and arrays?

They are serialised as compact JSON strings and stored in a JSONB column (PostgreSQL), a JSON column (MySQL), or a text column (SQLite, SQL Server), where the JSON functions of each database can query them. If you want separate columns instead, flatten the data first, for example with JSON to CSV.

Why are all identifiers quoted?

Quoting makes any JSON key a legal column name, including reserved words like order or user, keys with spaces or dashes, and mixed case. In PostgreSQL a quoted name keeps its case, so "userId" must be queried as "userId" — rename keys to snake_case before converting if you prefer unquoted names.

Are big integers kept exactly?

Yes. Numbers are copied digit for digit from the JSON text, so an ID like 9007199254740993 is inserted as 9007199254740993 into a BIGINT column, not rounded the way JavaScript would round it.

Is my data uploaded?

No. The SQL is generated in your browser and nothing is uploaded.

Last updated