JSON to SQL Converter
Generate typed MySQL, PostgreSQL or SQLite SQL from JSON
Processed in your browser without saving input. Input: up to 1 MiB, 5,000 rows, 200 columns and 64 nesting levels. SQL output: up to 4 MiB. Unsafe integers and numbers whose decimal value changes when parsed are rejected. Use strings for exact IDs, money or high-precision values.
Mixed types in a column are encoded as JSON: PostgreSQL JSONB, MySQL JSON, or JSON text in SQLite. Missing fields and null become SQL NULL. Inference does not create keys, indexes or business constraints; check the target schema first.
Generate SQL to see the result. Editing input or settings clears the previous result.
About this tool
JSON to SQL converts an object or a nonempty object array into MySQL, PostgreSQL or SQLite INSERT statements, with an optional starter CREATE TABLE. It reads only own properties, unions the input keys, and emits SQL NULL for missing fields and explicit null. A column with mixed types or nested values encodes every non-NULL value as JSON: JSONB in PostgreSQL, JSON in MySQL and JSON text in SQLite. Homogeneous strings, booleans and safe numbers use corresponding starter types. The parser rejects duplicate keys, unsafe integers, non-finite numbers and decimal tokens whose value changes during JavaScript number conversion. Non-integer SQL values use approximate floating-point types; exact IDs, money and high-precision values should be strings. Limits are 1 MiB, 5,000 rows, 200 columns and 64 nesting levels. Names, NUL and Unicode are checked before export. Generation stays in the browser, does not save input and never connects to a database. Review inferred types and your target schema before running the script. Generated SQL is capped at 4 MiB; increase batch size or reduce input if expansion exceeds this limit. The page previews the first 64 KiB, while copy and download contain the complete accepted output.
Scenario Recipes
Verify a mixed payload before seeding a database
Goal: Keep an object, a string and a missing field distinct.
- Paste [{"payload":{"x":1}},{"payload":"plain text"},{}], choose the target dialect and set table to events.
- Enable CREATE TABLE, generate and inspect payload: JSONB for PostgreSQL, JSON for MySQL or JSON text for SQLite.
- Execute in a temporary database and read back all three rows. The first value is an object, the second is a JSON string and the third is SQL NULL; review your actual schema before using the script elsewhere.
Result: A consistent column representation across mixed values, with SQL NULL for missing data.
Failure Clinic (Common Pitfalls)
Sparse JSON produces a much larger SQL script
Cause: Every row includes all observed columns, and small batches repeat the column list.
Fix: Increase rows per INSERT or use fewer rows. The generator rejects output above 4 MiB and never returns a partial script. Copy/download include the full accepted SQL even when the preview ends at 64 KiB.
A large JSON number is rejected
Cause: Numbers outside the JavaScript safe-integer range, non-finite values and decimal tokens that change value during parsing cannot be exported reliably by this generator.
Fix: Represent exact IDs, money and high-precision values as JSON strings. Supported non-integer numbers use approximate floating-point SQL types, not an inferred DECIMAL precision.
Different source types become one JSON column
Cause: One SQL column needs a coherent representation. A mix such as true and "word" is encoded as JSON for every non-NULL row.
Fix: Read the inferred type and the generated literals together. If a different SQL type is needed, normalize the source data deliberately or edit the schema and values together.
A JSON key cannot be used as a column
Cause: The portable name subset rejects empty names, control characters, outer whitespace, names above 63 UTF-8 bytes, and column names differing only by case. Duplicate JSON keys are also rejected.
Fix: Rename conflicting keys explicitly. Internal spaces, quotes, Unicode and dots are quoted as one column name; only the separate table field interprets a dot as schema.table.
Production Snippets
Mixed JSON columns encode strings as JSON strings
sql
-- Input: [{"payload":{"x":1}},{"payload":"plain text"},{}]
-- Dialect: PostgreSQL; table: events
CREATE TABLE "events" ("payload" JSONB);
INSERT INTO "events" ("payload") VALUES
(E'{"x":1}'),
(E'"plain text"'),
(NULL);
-- The double quotes around plain text belong to the JSON value.
-- Missing fields and explicit null both become SQL NULL.Frequently Asked Questions
How are mixed values in one column represented?
Every non-NULL value in a mixed or nested column is JSON-encoded. An ordinary string becomes a JSON string including its double quotes. PostgreSQL uses JSONB, MySQL JSON and SQLite TEXT containing JSON.
What happens to missing fields and special keys?
Only own properties are read. A missing constructor or __proto__ becomes SQL NULL; explicitly present keys retain their values. Explicit JSON null also becomes SQL NULL.
Can I convert 9007199254740993 as a JSON number?
No. It exceeds the JavaScript safe-integer range and would round during parsing. Use "9007199254740993" as a string. Precision-losing decimal tokens and non-finite numbers are also rejected; floating-point SQL columns are approximate.
Which column and table names are allowed?
Columns use 1–63 UTF-8 bytes with no control characters or outer whitespace; internal spaces, quotes, Unicode and dots are quoted literally. Duplicate JSON keys and columns differing only by case are rejected. The separate table field accepts ASCII table or schema.table.
What does CREATE TABLE inference include?
It suggests types from the supplied values. It does not infer primary keys, indexes, foreign keys, defaults or business constraints. If CREATE TABLE is disabled, ensure the existing schema matches the generated literals.
Does the tool run SQL or keep my input?
No. It generates text locally, does not connect to a database and does not save input. NUL and unpaired Unicode surrogates are unsupported. Editing input or settings invalidates the old output.
Keep browsing