Turn a JSON array into ready-to-run CREATE TABLE and INSERT statements, or turn a SQL query into clean JSON. One free tool, four database dialects, no signup.
What is JSON to SQL?
JSON to SQL means turning JSON data into statements a relational database understands. Typically that is a CREATE TABLE statement that defines the columns and INSERT statements that load the rows. JSON is the default format of web APIs, exports and config files, while SQL databases expect rows and columns, so a conversion step sits between the two.
This JSON to SQL converter reads an array of objects, maps each key to a column, infers a sensible data type for it and writes SQL for the database you choose. The reverse direction, SQL to JSON, takes a query and produces the JSON expression that returns your result set as a JSON document.
How to convert JSON to SQL
- Paste your JSON or upload a
.jsonfile. Validate it first with the JSON formatter and validator if you are unsure it is well formed. - Choose your database (MySQL, PostgreSQL, SQLite or SQL Server) and name the table.
- Click convert. The tool generates the table definition and the insert statements.
- Copy or download the SQL and run it in your database client.
Example input:
[
{"id": 1, "name": "Alice", "email": "alice@example.com", "active": true, "tags": ["admin", "editor"]},
{"id": 2, "name": "Bob", "email": "bob@example.com", "active": false, "tags": []}
]
PostgreSQL output:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255),
active BOOLEAN,
tags JSONB
);
INSERT INTO users (id, name, email, active, tags) VALUES
(1, 'Alice', 'alice@example.com', TRUE, '["admin","editor"]'),
(2, 'Bob', 'bob@example.com', FALSE, '[]');
Want the result tidy before you share it? Run it through the SQL formatter.
How to convert SQL data into JSON format
To convert a SQL query to JSON, you wrap a normal SELECT in your database’s JSON functions. The syntax differs for every engine, which is why a generator saves time. Enter your query and pick a dialect, and the tool produces the right expression:
| Database | SQL to JSON expression |
|---|---|
| PostgreSQL | SELECT json_agg(t) FROM (SELECT id, name FROM users) t; |
| MySQL | SELECT JSON_ARRAYAGG(JSON_OBJECT('id', id, 'name', name)) FROM users; |
| SQL Server | SELECT id, name FROM users FOR JSON PATH; |
| SQLite | SELECT json_group_array(json_object('id', id, 'name', name)) FROM users; |
All four return the same JSON: [{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}].
Converting JSON to a SQL table
When you convert JSON to a SQL table, the hardest part is choosing column types. The converter reads your values and maps them like this:
| JSON value | PostgreSQL | MySQL | SQLite | SQL Server |
|---|---|---|---|---|
| String | VARCHAR / TEXT | VARCHAR / TEXT | TEXT | NVARCHAR |
| Integer | INT / BIGINT | INT / BIGINT | INTEGER | INT / BIGINT |
| Decimal | DOUBLE PRECISION | DOUBLE | REAL | FLOAT |
| Boolean | BOOLEAN | TINYINT(1) | INTEGER | BIT |
| Date string | DATE / TIMESTAMP | DATE / DATETIME | TEXT | DATE / DATETIME2 |
| Object / array | JSONB | JSON | TEXT | NVARCHAR(MAX) |
Check the generated types before you load production data. Inference works from the values it sees, so a column that is whole numbers in your sample but decimals later may need a manual change.
How nested JSON is handled
Real-world JSON is rarely flat. Objects inside objects and arrays of values do not map to one plain column, so you have three common options: store the fragment in a JSON column (JSONB in PostgreSQL, JSON in MySQL, text in SQLite), flatten it into extra columns, or split arrays into a separate table linked by a key. JSON columns are quickest; related tables are best when you need to filter, join or index on the inner values.
Benefits of using JSON to SQL
Saves time
No hand-writing hundreds of INSERT lines or guessing column types.
Fewer errors
Quotes, apostrophes and special characters are escaped consistently.
Queryable data
Once in tables, you can filter, join, index and aggregate with plain SQL.
Works both ways
Go from API response to database and from database back to JSON.
In short, the main benefit of converting JSON to SQL is that you keep the flexibility of JSON for exchange while gaining the structure, constraints and speed of a relational database for storage and reporting.
Parse JSON in SQL: built-in functions
Every major database can also parse JSON stored in a column, which is useful when you decide to keep a nested fragment as JSON. A few functions to know:
- PostgreSQL: operators like
->and->>, plusjsonb_array_elements. See the PostgreSQL JSON types documentation. - MySQL:
JSON_EXTRACT,JSON_TABLEand the->>shortcut. See the MySQL JSON data type reference. - SQL Server:
ISJSON,JSON_VALUE,JSON_QUERYandOPENJSON. See Microsoft’s JSON data in SQL Server guide. - SQLite:
json_extract,json_eachandjson_group_array. See the SQLite JSON functions page.
If you need the exact rules for what counts as valid JSON, the format is defined in RFC 8259.
Common use cases
- Importing API data: save a REST API response into a table for reporting.
- NoSQL to SQL migration: move MongoDB or Firebase exports into MySQL or PostgreSQL.
- Seeding test databases: turn sample JSON fixtures into repeatable seed scripts.
- WordPress and WooCommerce work: load exported product or order data into a custom table.
- Feeding front ends: convert a SQL query to JSON for charts, dashboards and apps.
- Other formats: need a spreadsheet instead? Use the JSON to CSV converter.
Best practices
- Validate first. A stray comma or a single-quoted key will stop any parser.
- Test on a copy. Run generated SQL on a development database before production.
- Add keys and indexes. Set primary keys, unique constraints and indexes that match how you query.
- Use parameterized queries in code. Generated scripts suit one-off imports; applications should bind values rather than build SQL strings. The OWASP SQL Injection Prevention Cheat Sheet explains why.
- Batch large imports. Split very large inserts into several statements to stay under size limits.
Frequently asked questions
What is JSON to SQL?
It is the conversion of JSON objects into relational database statements, usually a CREATE TABLE definition plus INSERT statements for each record.
How do I convert JSON to SQL?
Paste a JSON array of objects, choose your database and table name, then click convert. Copy the generated SQL into your database client and run it.
How do I convert SQL data into JSON format?
Wrap your SELECT in your database’s JSON functions: json_agg in PostgreSQL, JSON_ARRAYAGG in MySQL, FOR JSON PATH in SQL Server or json_group_array in SQLite.
Can I convert a single JSON object?
Yes. A single object is treated as one row.
Can it handle nested JSON?
Yes. Nested objects and arrays can be kept in a JSON column where the database supports it, or stored as text or flattened.
Which databases are supported?
MySQL, PostgreSQL, SQLite and SQL Server. For MariaDB, start from the MySQL output.
Is the converter free?
Yes, it is free with no signup.
How do I convert other formats to JSON?
Try the XML to JSON converter for XML files.