jsonsql.dev100% client-side
SQL

JSON ↔ SQL Converter

Convert between JSON data and SQL statements — MySQL, PostgreSQL, SQLite

Loading JSON ↔ SQL Converter...

How to convert JSON to SQL online

jsonsql.dev converts JSON arrays to SQL INSERT statements instantly in your browser — supporting MySQL, PostgreSQL, and SQLite syntax with automatic type detection. No data is sent to any server.

Paste your JSON — paste a JSON array of objects into the input editor. Each object becomes a row, each key becomes a column. You can also drag-and-drop a .json file.

Configure options — set the table name, choose your SQL dialect (MySQL, PostgreSQL, or SQLite), select the output mode (CREATE TABLE + INSERT, INSERT only, etc.), and toggle options like IF NOT EXISTS or batch inserts.

Copy or download — click Copy to copy the generated SQL to your clipboard, or Download to save it as a .sql file. The SQL is ready to execute in your database.

How to convert SQL to JSON

jsonsql.dev parses SQL CREATE TABLE and INSERT statements directly in your browser, converting them to structured JSON data without needing a database connection.

Switch to SQL → JSON mode — click the "SQL → JSON" tab at the top of the tool. The input and output panels swap direction.

Paste your SQL — copy CREATE TABLE or INSERT INTO statements from your database dump, migration file, or SQL editor and paste them into the input panel.

Choose output mode — select Data (JSON array from INSERT), Schema (JSON Schema from CREATE TABLE), or Both to get the complete output. Then copy or download the result.

Example: JSON to SQL conversion

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": "Charlie", "email": null, "active": true }
]

Output SQL (PostgreSQL):

CREATE TABLE IF NOT EXISTS "data" (
  "id" INTEGER,
  "name" TEXT,
  "email" TEXT,
  "active" BOOLEAN
);

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

Example SQL to JSON (Data mode):

-- Input SQL:
CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255),
  age INT DEFAULT 0,
  active BOOLEAN DEFAULT true
);

INSERT INTO users (id, name, email, age, active) VALUES
(1, 'Alice', 'alice@example.com', 30, true),
(2, 'Bob', 'bob@example.com', 25, false),
(3, 'Charlie', NULL, 35, true);

-- Output JSON:
[
  { "id": 1, "name": "Alice", "email": "alice@example.com", "age": 30, "active": true },
  { "id": 2, "name": "Bob", "email": "bob@example.com", "age": 25, "active": false },
  { "id": 3, "name": "Charlie", "email": null, "age": 35, "active": true }
]

JSON to SQL type mapping

jsonsql.dev automatically detects the JSON value type and maps it to the appropriate SQL column type for each dialect.

JSON typeMySQLPostgreSQLSQLite
stringVARCHAR(255)TEXTTEXT
number (integer)INTINTEGERINTEGER
number (float)DOUBLEDOUBLE PRECISIONREAL
booleanTINYINT(1)BOOLEANINTEGER
nullNULLNULLNULL
array / objectJSONJSONBTEXT

SQL type to JSON type mapping

When converting SQL to JSON, each SQL data type maps to its closest JSON equivalent.

SQL TypeJSON TypeNotes
INT, INTEGER, BIGINT, SMALLINTnumberAll integer types map to number
FLOAT, DOUBLE, DECIMAL, NUMERIC, REALnumberFloating-point types map to number
VARCHAR, CHAR, TEXT, CLOBstringAll text types map to string
BOOLEAN, BOOL, TINYINT(1)booleanBoolean types and MySQL TINYINT(1)
JSON, JSONBobjectPostgreSQL JSON types
DATE, DATETIME, TIMESTAMPstringDate/time stored as ISO 8601 strings
BLOB, BINARY, BYTEAstringBinary data stored as base64 strings
UUIDstringUUID stored as string
SERIAL, BIGSERIALnumberPostgreSQL auto-increment types
ENUMstringEnum values stored as strings

SQL dialect differences

Each SQL dialect has its own syntax quirks. Here is how jsonsql.dev handles the differences between MySQL, PostgreSQL, and SQLite.

FeatureMySQLPostgreSQLSQLite
Identifier quotingBackticks `name`Double quotes "name"Double quotes "name"
Boolean values1 / 0TRUE / FALSE1 / 0
String escapingBackslash + single quoteDouble single quoteDouble single quote
JSON column typeJSONJSONBTEXT
DROP TABLE syntaxDROP TABLE IF EXISTSDROP TABLE IF EXISTSDROP TABLE IF EXISTS
Auto-incrementAUTO_INCREMENTSERIAL / GENERATEDAUTOINCREMENT

Common use cases

  • API data import — you fetched data from a REST API as JSON and need to import it into your relational database. Convert the JSON response to INSERT statements and run them directly.
  • Data migration — migrating from a NoSQL database (MongoDB, Firebase) to a relational database (MySQL, PostgreSQL), or vice versa. Export as JSON, convert to SQL, or extract SQL to JSON.
  • Test fixtures and seed data — generate SQL INSERT statements from JSON test data files to seed your development or staging database, or convert SQL dumps to JSON fixtures for unit tests.
  • Quick prototyping — define your data structure in JSON (which is easy to write), then generate the CREATE TABLE statement to bootstrap your database schema.
  • Database export to JSON — convert database dumps to JSON for use in APIs, documentation, or data analysis without running a database.
  • API mocking — generate JSON fixtures from SQL schema for frontend development and testing without a backend.
  • Spreadsheet to database — export spreadsheet data as JSON (via CSV-to-JSON), then convert to SQL for database import.
  • Log analysis — convert JSON log entries to SQL for analysis using familiar SQL queries instead of JSON-specific tools.

Code examples

Python: JSON to SQL

import json

with open('data.json') as f:
    rows = json.load(f)

cols = list(rows[0].keys())
table = 'data'

print(f"CREATE TABLE {table} ({', '.join(f'{c} TEXT' for c in cols)});")
for row in rows:
    vals = ', '.join(
        'NULL' if row.get(c) is None else f"'{row[c]}'"
        for c in cols
    )
    print(f"INSERT INTO {table} ({', '.join(cols)}) VALUES ({vals});")

Python: SQL to JSON

import json, sqlite3

conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE users (id INT, name TEXT, email TEXT)')
conn.execute("INSERT INTO users VALUES (1, 'Alice', 'alice@example.com')")
conn.execute("INSERT INTO users VALUES (2, 'Bob', 'bob@example.com')")

cursor = conn.execute('SELECT * FROM users')
cols = [d[0] for d in cursor.description]
rows = [dict(zip(cols, row)) for row in cursor.fetchall()]
print(json.dumps(rows, indent=2))

Node.js: JSON to SQL

const fs = require('fs');
const rows = JSON.parse(fs.readFileSync('data.json', 'utf8'));
const cols = Object.keys(rows[0]);
const table = 'data';

console.log(`CREATE TABLE ${table} (${cols.map(c => `${c} TEXT`).join(', ')});`);
rows.forEach(row => {
  const vals = cols.map(c =>
    row[c] === null ? 'NULL' : `'${String(row[c]).replace(/'/g, "''")}'`
  ).join(', ');
  console.log(`INSERT INTO ${table} (${cols.join(', ')}) VALUES (${vals});`);
});

CLI with jq + sqlite3

# Generate INSERT statements from JSON array
cat data.json | jq -r '.[] | "INSERT INTO data VALUES (\(.id), '"'"'\(.name)'"'"', '"'"'\(.email)'"'"');"'

# Convert SQLite database to JSON
sqlite3 -json database.db "SELECT * FROM users" | jq '.'

Comparison: JSON ↔ SQL tools

Featurejsonsql.devManual conversionDatabase CLI (mysql/psql)
Browser-basedYesN/ANo (CLI)
Client-side only (no upload)YesYesYes (local)
Bidirectional (JSON ↔ SQL)YesManualOne-way
Auto type detectionYesNo (manual)Partial
Multiple SQL dialectsMySQL, PostgreSQL, SQLiteManualOne at a time
CREATE TABLE generationYesManualRequires existing table
Nested JSON flatteningYes (underscore)ManualNo
Batch INSERT supportYes (configurable)ManualYes (bulk)
Parses CREATE TABLE to JSONYesManualNo
No install neededYesYesNo
Works offlineYesYesYes

Related tools

Frequently asked questions

What SQL types does JSON map to?

JSON strings map to VARCHAR(255) in MySQL or TEXT in PostgreSQL/SQLite. Numbers map to INT or DOUBLE/DOUBLE PRECISION. Booleans map to TINYINT(1) in MySQL or BOOLEAN in PostgreSQL. Nested objects and arrays map to JSON/JSONB/TEXT depending on the dialect.

Can I convert nested JSON to SQL?

Yes. jsonsql.dev flattens nested objects using underscores — for example, address.city becomes address_city. Nested arrays and objects that cannot be flattened are stored as JSON/JSONB/TEXT columns.

What are the differences between MySQL, PostgreSQL, and SQLite dialects?

The converter supports MySQL (backtick-quoted identifiers, TINYINT(1) for booleans, backslash escaping), PostgreSQL (double-quoted identifiers, BOOLEAN, JSONB, SERIAL types), and SQLite (double-quoted identifiers, TEXT for most types, no native BOOLEAN). Each dialect generates idiomatic SQL.

What is the difference between INSERT and batch INSERT?

A single INSERT creates one statement per row (INSERT INTO ... VALUES (...)). Batch INSERT groups multiple rows into a single statement (INSERT INTO ... VALUES (...), (...), (...)). Batch inserts are faster for large datasets because they reduce the number of round-trips to the database.

Does it handle NULL values correctly?

Yes. JSON null values are converted to SQL NULL (without quotes). When converting SQL to JSON, SQL NULL is correctly mapped to JSON null. The converter properly distinguishes between null, empty strings, and the string "null".

What happens with inconsistent keys across JSON objects?

jsonsql.dev collects ALL unique keys from ALL objects in the array. If an object is missing a key, the value is set to NULL in the INSERT statement. This ensures the generated SQL handles sparse or inconsistent JSON data correctly.