jsonsql.dev 100% client-side
SQL

JSON ↔ SQL Converter

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

JSON Input
SQL Output
ReadyCtrl+Enter convert · Ctrl+Shift+C copy

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 type MySQL PostgreSQL SQLite
string VARCHAR(255) TEXT TEXT
number (integer) INT INTEGER INTEGER
number (float) DOUBLE DOUBLE PRECISION REAL
boolean TINYINT(1) BOOLEAN INTEGER
null NULL NULL NULL
array / object JSON JSONB TEXT

SQL type to JSON type mapping

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

SQL Type JSON Type Notes
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.

Feature MySQL PostgreSQL SQLite
Identifier quoting Backticks `name` Double quotes "name" Double quotes "name"
Boolean values 1 / 0 TRUE / FALSE 1 / 0
String escaping Backslash + single quote Double single quote Double single quote
JSON column type JSON JSONB TEXT
DROP TABLE syntax DROP TABLE IF EXISTS DROP TABLE IF EXISTS DROP TABLE IF EXISTS
Auto-increment AUTO_INCREMENT SERIAL / GENERATED AUTOINCREMENT

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

Feature jsonsql.dev Manual conversion Database CLI (mysql/psql)
Browser-based Yes N/A No (CLI)
Client-side only (no upload) Yes Yes Yes (local)
Bidirectional (JSON ↔ SQL) Yes Manual One-way
Auto type detection Yes No (manual) Partial
Multiple SQL dialects MySQL, PostgreSQL, SQLite Manual One at a time
CREATE TABLE generation Yes Manual Requires existing table
Nested JSON flattening Yes (underscore) Manual No
Batch INSERT support Yes (configurable) Manual Yes (bulk)
Parses CREATE TABLE to JSON Yes Manual No
No install needed Yes Yes No
Works offline Yes Yes Yes

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.

How does the converter handle SQL reserved words as column names?

Column names that are SQL reserved words (like "order", "group", "select", "user") are automatically quoted using the dialect-appropriate syntax — backticks for MySQL, double quotes for PostgreSQL and SQLite. This prevents syntax errors without requiring you to rename your JSON keys.

Can I convert JSON with date strings to SQL TIMESTAMP or DATE columns?

The converter currently maps all JSON strings to VARCHAR or TEXT. It does not auto-detect ISO 8601 date strings as DATE or TIMESTAMP types. After generating the SQL, you can manually change the column type in the CREATE TABLE statement to TIMESTAMP or DATE for date fields.

Is the generated SQL safe from SQL injection?

The converter escapes single quotes inside string values by doubling them (standard SQL escaping). However, the generated SQL is intended for development, migration scripts, and data seeding — not for direct use in user-facing applications. Always use parameterized queries in production code.

How do I convert a JSON array with 10,000+ rows to SQL efficiently?

Use the batch INSERT option to group rows into multi-value INSERT statements (e.g., 500 rows per statement). This reduces the total number of SQL statements and is 5-10x faster to execute than individual INSERTs. The tool runs client-side, so arrays up to ~50,000 rows typically process in a few seconds.