How to use the json to sql converter
- Paste a JSON array of objects into the input field. Each object becomes one row in the generated SQL.
- Enter a table name. Use only letters, numbers and underscores to ensure valid SQL syntax.
- Select your target SQL dialect to get matching column types like
JSONBfor PostgreSQL orJSONfor MySQL. - The output updates automatically with a
CREATE TABLEstatement followed byINSERT INTOstatements.
How the json to sql conversion works
The json to sql converter parses your input using the built-in JSON.parse function and expects an array of objects. It collects every unique key across all objects to build the column list, preserving the order in which keys first appear.
For each value, the tool infers a SQL type. Numbers without a fractional part become INTEGER, numbers with decimals become REAL (or DOUBLE PRECISION in PostgreSQL), booleans map to BOOLEAN, and strings map to TEXT or VARCHAR(255) depending on the dialect. Nested objects and arrays are serialized back to JSON strings and stored in TEXT, JSONB or JSON columns.
String values are escaped by doubling any single quotes. For example, O'Reilly becomes O''Reilly in the output. Null values are written as the unquoted keyword NULL.
Type mapping reference
The following table shows how JavaScript types map to SQL column types in each supported dialect when you convert json to sql.
| JavaScript type | Generic | PostgreSQL | MySQL |
|---|---|---|---|
| Integer number | INTEGER | INTEGER | INT |
| Decimal number | REAL | DOUBLE PRECISION | DOUBLE |
| String | TEXT | TEXT | VARCHAR(255) |
| Boolean | BOOLEAN | BOOLEAN | BOOLEAN |
| Object or Array | TEXT | JSONB | JSON |
| null (only) | TEXT | TEXT | VARCHAR(255) |
When a column contains mixed types across rows, whole numbers mixed with decimals become a decimal column, integers beyond the 32-bit range become BIGINT, and any other mix falls back to a text column so no value is lost.
Handling nested objects and arrays
Relational databases store flat rows, so nested JSON structures need special handling. When the converter encounters an object or array as a value, it serializes that value back into a compact JSON string using JSON.stringify.
For example, if a row contains {"tags": ["admin", "user"]}, the generated INSERT statement will include '["admin","user"]' as a string literal. In PostgreSQL you can use the JSONB type to query inside these values efficiently. In MySQL the JSON type offers similar capabilities.
If you prefer to flatten nested objects into separate columns before converting, you can use a JSON flattening tool first, then paste the result here.
Common mistakes to avoid
The most frequent error is pasting a single JSON object instead of an array. The converter requires an array of objects because each object represents one database row. Wrap your object in square brackets: [{"id": 1}] instead of {"id": 1}.
Another issue is using reserved SQL words as table names or keys without quoting them. The converter quotes table and column names automatically when they contain spaces or symbols, start with a digit, or are common reserved words (double quotes, or backticks for MySQL).
Finally, be aware that very large JSON inputs will produce correspondingly large SQL output. If you only need to inspect the data visually rather than import it, consider using a JSON table viewer or converting to a HTML table or Markdown table instead.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple user records | JSON input: [{"id": 1, "name": "Alice", "email": "alice@example.com"}, {"id": 2, "name": "Bob", "email": null}]; Table name: users; SQL dialect: generic | CREATE TABLE users ( / id INTEGER, / "name" TEXT, / email TEXT / ); / INSERT INTO users (id, "name", email) VALUES (1, 'Alice', 'alice@example.com'); / INSERT INTO users (id, "name", email) VALUES (2, 'Bob', NULL); |
| Nested object as JSON string | JSON input: [{"id": 1, "profile": {"age": 30, "city": "London"}}]; Table name: accounts; SQL dialect: postgresql | CREATE TABLE accounts ( / id INTEGER, / profile JSONB / ); / INSERT INTO accounts (id, profile) VALUES (1, '{"age":30,"city":"London"}'); |
| Array values and booleans | JSON input: [{"id": 1, "tags": ["admin", "user"], "active": true}]; Table name: roles; SQL dialect: mysql | CREATE TABLE roles ( / id INT, / tags JSON, / active BOOLEAN / ); / INSERT INTO roles (id, tags, active) VALUES (1, '["admin","user"]', 1); |
FAQ
What JSON structure does this json to sql converter accept?
It accepts a JSON array where each element is an object. Each object becomes a row in the resulting SQL INSERT statements. Primitive arrays or single objects are not accepted because they do not map cleanly to relational rows.
How are nested objects and arrays handled?
Nested objects and arrays are serialized back into JSON strings. They are inserted as text literals and mapped to TEXT, JSONB or JSON column types depending on the selected SQL dialect.
Does the converter handle null values?
Yes. Null values in the JSON input are converted to the SQL keyword NULL without quotes. If an entire column contains only nulls, the type defaults to TEXT.
Are single quotes in strings escaped?
Yes. Single quotes inside string values are doubled, which is the standard SQL escaping method. For example, O'Reilly becomes O''Reilly in the output.
Can I use this for large datasets?
The tool processes everything in memory in your browser. It works well for hundreds or thousands of rows, but extremely large files may cause the browser tab to slow down. Split very large files into smaller chunks if needed.
Is my data sent to a server?
No. The conversion happens entirely in your browser using JavaScript. Your JSON input and the generated SQL never leave your device.