Find your next tool

Browse tools or search by task

Explore JSONToonPro

JSON Tools

JSON to SQL Converter – Generate INSERT & CREATE TABLE

Convert JSON to SQL INSERT statements and CREATE TABLE schemas online. Map object fields to columns and generate database-ready SQL in your browser.

Runs locally in your browser. Nothing you paste is uploaded.

JSON to SQL workspace
3 x 9
Input/ JSON
749 chars41 lines
Output/ PostgreSQL SQL
704 chars18 lines

How to Convert JSON to SQL

Paste sample JSON records, choose a table name and review the generated statements. This is a script generator, not a database connection. Test generated SQL in an isolated database before using it on important data.

Generating CREATE TABLE From JSON

CREATE TABLE generation infers columns and candidate types from examples. One sample cannot establish all future values, lengths, indexes or nullability rules. Treat the generated schema as a starting point and adapt it to your SQL dialect.

Generating INSERT Statements

INSERT statements map object fields to columns and encode row values. Confirm column names, quoting and null handling. Large batches may need splitting to fit server limits or transaction policies.

Mapping JSON Types to SQL Types

JSON strings, numbers and booleans need SQL types appropriate to the target database. Nested objects can be serialized into text or handled separately. Dates are strings until you explicitly choose and validate a date type.

Escaping Values and SQL Safety

Escaping a generated literal is not a substitute for parameterized queries in application code. Review identifiers as well as values. Do not execute generated statements without understanding the table and data they affect.

More examples and technical details

From an Array to a Table

Generating SQL from JSON is really two jobs. The first is inferring a schema: scanning every record to work out which columns exist and what type each one should be. The second is serialising the values into INSERT statements with correct quoting and escaping.

The schema is inferred from the union of keys across all records, not just the first one, because JSON arrays are frequently ragged. A key that appears in only some records still needs a column, and the records that lack it get NULL. If a key holds a number in one record and a string in another, the widening rule applies and the column becomes text, since text can hold anything.

Side by Side Example

An orders array and the DDL plus DML it generates.

JSON input

[
{ "order_id": 1001,
"customer": "Nadia O'Brien",
"total": 249.99,
"paid": true,
"shipped_at": null },
{ "order_id": 1002,
"customer": "Ravi Patel",
"total": 18.00,
"paid": false,
"shipped_at": "2025-02-14" }
]

SQL output

CREATE TABLE orders (
order_id INTEGER,
customer VARCHAR(255),
total DECIMAL(12,2),
paid BOOLEAN,
shipped_at VARCHAR(255)
);
 
INSERT INTO orders
(order_id, customer, total, paid, shipped_at)
VALUES
(1001, 'Nadia O''Brien', 249.99, TRUE, NULL),
(1002, 'Ravi Patel', 18.00, FALSE, '2025-02-14');

The apostrophe in the customer name is escaped by doubling it, which is the SQL standard mechanism. The null stays a real NULL rather than the four character string.

Type Inference Mapping

JSON typeTypical SQL typeNotes
String, shortVARCHAR(255)Length chosen from the longest observed value, rounded up
String, long or unboundedTEXTAnything over a few hundred characters
Integer within 32 bitsINTEGERSafe for ids and counts
Integer beyond 32 bitsBIGINTTimestamps in milliseconds land here
Float, money-likeDECIMAL(12,2)Never use a binary float for currency
Float, scientificDOUBLE PRECISIONMeasurements and ratios
BooleanBOOLEAN or TINYINT(1)MySQL has no true boolean type
Null only, no other valuesTEXT NULLNothing to infer from, widen to text
ISO date stringDATE or TIMESTAMPOnly if you opt into date detection
ObjectJSON, JSONB, or a child tableDepends on how you will query it
ArrayJSON, JSONB, or a join tableSame decision, see normalisation below

Inferred lengths are a starting point, not a contract. If your sample happens to contain no name longer than forty characters, a VARCHAR sized to that sample will reject real data later. Widen anything that a user can type into.

Dialect Differences

FeatureMySQLPostgreSQLSQLite
Identifier quotingBackticksDouble quotesEither
Auto increment keyAUTO_INCREMENTSERIAL or IDENTITYINTEGER PRIMARY KEY
BooleanTINYINT(1), 0 and 1Native BOOLEAN, TRUE and FALSEStored as 0 and 1
JSON columnJSONJSON and JSONB, JSONB preferredTEXT with JSON functions
Text typeVARCHAR or TEXTTEXT, no length penaltyTEXT, types are advisory
Multi-row insertSupportedSupportedSupported since 3.7.11
UpsertON DUPLICATE KEY UPDATEON CONFLICT DO UPDATEON CONFLICT DO UPDATE

PostgreSQL folds unquoted identifiers to lower case while MySQL on Linux is case sensitive for table names but not column names. The simplest way to avoid ever thinking about this is to generate snake_case identifiers and never quote them.

Handling Nested Objects and Arrays

Relational tables are flat, so nested JSON forces a modelling decision. There are three options and the right one depends entirely on how you intend to query the data.

StrategyResultGood whenCost
Flatten with dot or underscore pathsaddress_city, address_postcode columnsNesting is shallow and fixedColumn explosion if the shape varies
Store as a JSON columnOne address column holding the objectShape varies or you rarely filter on itIndexing and joining are awkward
Normalise into a child tableAn addresses table with a foreign keyYou query, join, or aggregate on itMore work up front, more joins later

Arrays of scalars can live in a JSON column comfortably. Arrays of objects almost always want their own table, because a line items array inside an orders row is a one to many relationship pretending not to be one. Generated SQL will usually take the JSON column route since it is the only option that never loses data, and promoting it to a proper child table is a deliberate follow up step.

A Warning About Generated SQL

Generated statements are for schema bootstrapping and seeding: creating a table from a sample payload, loading fixtures into a development database, or getting a prototype moving. That is a safe use because you control the input and you can read the output before running it.

String concatenation is never acceptable in application code. Building a query by interpolating values into a string is the definition of a SQL injection vulnerability, and escaping by hand does not save you: encodings, multi-byte characters, and dialect specific escape modes all provide ways around a naive escaper.

Never versus always

// Never, in any language, for any reason
db.query("SELECT * FROM users WHERE email = '" + input + "'");
 
// Always, parameters sent separately from the statement
db.query("SELECT * FROM users WHERE email = $1", [input]);

Two more habits worth keeping. Review generated DDL before you run it, since inferred types and lengths reflect one sample rather than your real domain. And add the things inference cannot see: primary keys, foreign keys, unique constraints, NOT NULL, and the indexes your queries will actually need.

Getting data into a database is one step in a longer pipeline. See the full converter collection for JSON to CSV when your loader prefers a bulk import file, JSON Schema to validate payloads before they ever reach the database, and JSON to TypeScript to type the rows in your application layer.

Standards and references

Frequently asked questions

How do I turn JSON into SQL INSERT statements?

Paste a JSON array of records and choose the INSERT output options.

Can the tool generate CREATE TABLE SQL?

Yes. Review inferred types, constraints and dialect details before using the DDL.

How are nested JSON objects handled?

Nested values may be serialized; decide whether a JSON column or normalized tables better fit your application.

Does generated SQL prevent injection by itself?

No. Use parameterized queries for runtime input and review generated SQL before execution.

Is JSON processed locally?

Yes. The generator creates text locally and does not connect to a database.