JSON SQL

JSON to SQL Converter (Free AI Tool)

Convert JSON to SQL INSERT statements and table schemas for relational database import. Generate CREATE TABLE definitions with inferred data types (INT, VARCHAR, TIMESTAMP) and INSERT queries for MySQL, PostgreSQL, SQLite. Transform API responses and NoSQL data into normalized relational structures.

Data Format Converter
Tools
JSON Input
Ready to convert
JSON Output
Converted output will appear here

Hint: Select conversion type, paste your data, and get instant conversion. Supports JSON, YAML, XML, Excel, PDF, and more.

Client-side only

How It Works

  1. 1

    Paste JSON Objects or Arrays

    Input your JSON from REST API responses, MongoDB exports, or data files. Arrays of objects work best for generating table rows.

  2. 2

    AI Infers SQL Types and Generates Schema

    The AI analyzes JSON values to infer SQL data types: numbers become INT or DECIMAL, strings become VARCHAR with appropriate length, booleans become BOOLEAN, and ISO dates become TIMESTAMP. Generates CREATE TABLE with PRIMARY KEY and appropriate constraints.

  3. 3

    Copy SQL CREATE and INSERT Statements

    Receive SQL with CREATE TABLE definition followed by INSERT statements for each JSON object. The SQL is compatible with MySQL, PostgreSQL, SQLite, and SQL Server. Ready to execute in your database client.

JSON vs SQL: Data Storage Comparison

Feature JSON (Document) SQL (Relational)
Data Structure Nested documents Normalized tables
Schema Schema-less (flexible) Fixed schema (CREATE TABLE)
Arrays Native array support Separate tables (1:N)
Queries Key-based access SQL SELECT with JOINs
Type System JSON types (string, number, bool) SQL types (VARCHAR, INT, BOOLEAN)
Use Case APIs, NoSQL databases Relational databases, analytics

Code Examples

Example 1: Simple JSON Array to Table

JSON Input
[
  {"id": 1, "username": "johndoe", "email": "[email protected]", "active": true},
  {"id": 2, "username": "janedoe", "email": "[email protected]", "active": false},
  {"id": 3, "username": "bob", "email": "[email protected]", "active": true}
]
SQL Output
CREATE TABLE users (
  id INT PRIMARY KEY,
  username VARCHAR(50) NOT NULL,
  email VARCHAR(100) NOT NULL,
  active BOOLEAN NOT NULL
);

INSERT INTO users (id, username, email, active) VALUES
  (1, 'johndoe', '[email protected]', TRUE),
  (2, 'janedoe', '[email protected]', FALSE),
  (3, 'bob', '[email protected]', TRUE);

Key Changes:

JSON arrays convert to SQL tables with each object becoming a row. JSON keys (id, username, email) become column names. The converter infers data types: integers remain INT, strings become VARCHAR with length based on max value length, and booleans become BOOLEAN. The first numeric field is often designated as PRIMARY KEY. All INSERT values are properly escaped and quoted according to SQL standards. The generated SQL follows standard syntax compatible with MySQL, PostgreSQL, and SQLite.

Example 2: Nested Objects to Related Tables

JSON Input
[
  {
    "order_id": 101,
    "customer": {"name": "Alice", "email": "[email protected]"},
    "items": [{"product": "Laptop", "price": 999}, {"product": "Mouse", "price": 25}]
  }
]
SQL Output
CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  customer_name VARCHAR(100),
  customer_email VARCHAR(100)
);

CREATE TABLE order_items (
  id INT AUTO_INCREMENT PRIMARY KEY,
  order_id INT,
  product VARCHAR(100),
  price DECIMAL(10,2),
  FOREIGN KEY (order_id) REFERENCES orders(order_id)
);

INSERT INTO orders (order_id, customer_name, customer_email) VALUES
  (101, 'Alice', '[email protected]');

INSERT INTO order_items (order_id, product, price) VALUES
  (101, 'Laptop', 999.00),
  (101, 'Mouse', 25.00);

Key Changes:

Nested JSON objects are flattened into the parent table with prefixed columns (customer_name, customer_email). JSON arrays require separate related tables with foreign key relationships—the items array becomes an order_items table with a foreign key to orders. Decimal numbers (prices) convert to DECIMAL(10,2) for financial precision. The AUTO_INCREMENT on the items table generates unique IDs for the one-to-many relationship. This demonstrates JSON document denormalization into proper relational database normal forms with referential integrity constraints.

Frequently Asked Questions

How does the converter handle nested JSON objects?

Nested JSON can be handled two ways: (1) Flattening to columns with concatenated names (e.g., address_city, address_zip) for shallow nesting, or (2) Creating separate related tables with foreign keys for deep nesting. The converter analyzes structure depth and suggests normalized table designs. Complex nested arrays may require manual table relationship design for proper 1:N or N:M relationships.

Is my JSON data stored during conversion?

No. All JSON to SQL conversion happens entirely client-side in your browser using JavaScript-based parsing. Your API data, database exports, or sensitive records never leave your machine. The tool works offline once loaded.

What SQL dialects are supported for data types?

The converter generates standard SQL data types (VARCHAR, INT, BOOLEAN, DECIMAL, TIMESTAMP) compatible with MySQL, PostgreSQL, SQLite, and SQL Server. JSON numbers become INT or DECIMAL based on decimal presence. Dates in ISO 8601 format convert to TIMESTAMP or DATE. For dialect-specific types (e.g., PostgreSQL JSONB, MySQL TEXT vs MEDIUMTEXT), manual adjustment may be needed based on data size.

Related Tools