JSON to SQL Generator
Generate CREATE TABLE and INSERT statements from a JSON array. Infers column types and safely escapes string values. Runs entirely in your browser.
JSON array
How it works
- Paste a JSON array of objects — keys become columns, and types are inferred across all rows (integer →
INTEGER, float →REAL/DOUBLE, string →TEXT/VARCHAR, boolean →BOOLEAN). - Nested objects/arrays become
TEXTcolumns holding the JSON-encoded value. - String values are escaped by doubling single quotes; booleans become
TRUE/FALSE. - Missing keys are emitted as
NULL, so every row has the same column set.
About JSON to SQL Generator
When you receive data as JSON — an export, an API response, a fixture — but need it in a relational database, writing the DDL and INSERT statements by hand is tedious and error-prone. This tool derives the table structure from the data itself: every key becomes a column, and the type for each column is decided by looking at the values across all rows, so one stray string doesn’t make the whole column TEXT.
The generated statements target common dialects (MySQL, SQLite, PostgreSQL) and are safe to run: identifiers are validated, string literals are single-quote-escaped, and NULLs are explicit. This is a great way to seed test databases, convert spreadsheet-derived JSON, or move fixture data into SQL. For production use, review the column widths and add primary keys, constraints, and indexes — this tool focuses on getting the data in.
Type inference scans every row, in a fixed precedence
Columns are the union of keys across all objects in first-appearance order, and each column's type is decided by looking at every value in it, not just the first. The precedence is: any string anywhere makes the column text; otherwise any boolean makes it boolean; otherwise any non-integer number makes it float; otherwise any number makes it integer. That ordering is the behaviour to understand, because it is one-way — a single stray string among numbers widens the column to text, and no amount of numeric data narrows it back.
The mapping is `VARCHAR(255)` for text on MySQL and `TEXT` elsewhere, `REAL` on SQLite and `DOUBLE` elsewhere for float, `INTEGER`, `BOOLEAN`. The MySQL text case is the one to watch: `VARCHAR(255)` truncates or errors depending on the server's SQL mode, so a longer string that looked like plain text becomes a data-loss event. Boolean is checked before numeric, so a column mixing `true` and `1` is typed boolean while the `1` is still emitted as a bare integer literal.
Identifiers and values are handled by two different mechanisms
Identifiers are sanitised, then quoted. Every character outside `[A-Za-z0-9_]` becomes an underscore, and the result is wrapped in backticks for MySQL or double quotes for SQLite and PostgreSQL. That makes injection through a column or table name impossible, which is the right priority — but it is lossy without saying so: `user-name` and `user_name` both become `user_name`, two distinct keys collide into one column, and the generated `CREATE TABLE` contains the duplicate. Check the column names before running the DDL.
Values take the other path. String literals are escaped by doubling single quotes and nothing else — no backslash is escaped. That is correct for PostgreSQL and standard SQL, where backslash is ordinary. It is not correct for MySQL in default mode, where backslash escapes: a value ending in a backslash produces a literal whose closing quote is escaped, and everything after is parsed as SQL rather than data. A trailing `\` from untrusted input is enough to break the statement.
What is missing, and what the numbers do
There is no primary key, foreign key, unique constraint, check, index, `NOT NULL` or default in the output, and no auto-incrementing column — no `AUTO_INCREMENT`, `SERIAL` or `IDENTITY` for any dialect, so an integer key arrives as a plain `INTEGER` you must populate yourself. There is also no `CREATE TABLE IF NOT EXISTS` and no multi-row batching: one `INSERT` per object. Nested objects and arrays become text columns holding JSON, worth promoting to `jsonb` on PostgreSQL.
Numbers are written through JavaScript's string conversion, so a large integer beyond 2^53 is emitted already precision-damaged and a float such as `1.0` is emitted as `1`. Three dialects are offered — MySQL, SQLite and PostgreSQL — and booleans are bare `TRUE` and `FALSE`, accepted by all three in current versions but not by older SQLite builds. Treat the result as a draft: run it against a scratch database, then add the keys, constraints and indexes that make it a schema.
Frequently Asked Questions
How do I generate SQL from a JSON array?
Which SQL dialects are supported?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.