Javascript is required

JSON to SQL INSERT Converter

Generate one INSERT draft for an existing table. Review the mapping and database settings before execution.

Literal drafts do not include bound parameters. Use driver or ORM parameter binding for application writes.

SQL draft
-- Enter JSON to generate a draft

Four API payload cases

Load a case to replace the input, table name, dialect and flatten option together. Expected SQL below is available before JavaScript runs.

Nested API rows, missing keys and NULL

MySQL with flattening on: user.name becomes user_name, boolean values become 1 and 0, and the second row fills missing columns with NULL.

mysql · Table name: api_users · Flatten nested objects (user_name): true

Source JSON

[
  { "id": 1, "user": { "name": "Ada" }, "active": true, "note": null },
  { "id": 2, "active": false }
]

Expected SQL draft

INSERT INTO `api_users` (`id`, `user_name`, `active`, `note`)
VALUES
  (1, 'Ada', 1, NULL),
  (2, NULL, 0, NULL);

Missing data and explicit null share NULL. This does not infer defaults or NOT NULL constraints.

PostgreSQL quoted names and backslashes

Quotes inside table and column names are doubled. The path containing a backslash uses an E literal; its apostrophe is doubled and the boolean is TRUE.

postgres · Table name: audit"log · Flatten nested objects (user_name): true

Source JSON

{
  "odd\"key": "C:\\new\\O'Brien",
  "active": true
}

Expected SQL draft

INSERT INTO "audit""log" ("odd""key", "active")
VALUES
  (E'C:\\new\\O''Brien', TRUE);

The table name is one identifier. PostgreSQL is a selected output style; no server session is queried.

SQLite with nested JSON kept as text

Flattening is off: the object and array become compact JSON strings. The apostrophe inside JSON text is doubled for the SQL literal; false becomes 0.

sqlite · Table name: records · Flatten nested objects (user_name): false

Source JSON

{
  "id": 3,
  "user": {
    "name": "O'Brien"
  },
  "tags": [
    "red",
    "blue"
  ],
  "active": false
}

Expected SQL draft

INSERT INTO "records" ("id", "user", "tags", "active")
VALUES
  (3, '{"name":"O''Brien"}', '["red","blue"]', 0);

The tool does not create JSON columns or child tables. Check the receiving column types.

Conflicting flattened paths stop conversion

user_name and user.name would generate the same column. The converter reports an error and clears SQL instead of choosing one value.

mysql · Table name: records · Flatten nested objects (user_name): true

Source JSON

{ "user_name": "flat", "user": { "name": "nested" } }

Expected error

Nested paths map to the same column. Rename keys or turn flattening off.

Turn flattening off or change keys to resolve the collision; the same check applies across rows.

Map API payloads to INSERT drafts

Paste JSON, set one table name, choose a dialect and check the flatten option. Columns follow the first encountered keys across rows; missing fields and explicit null both become SQL NULL. Copy or download the draft after reviewing it.

MySQL identifiers use backticks; PostgreSQL and SQLite use double quotes. Identifier quotes are doubled. A table name such as public.users is quoted as one name, not a schema-qualified path. No CREATE TABLE, database connection or parameter binding is generated.

Usage Boundaries & Limitations

  • Flattening joins nested object keys with underscores. Arrays remain JSON text; with flattening off, objects also remain JSON text. Distinct paths that produce the same column are rejected, including across rows. Empty nested objects contribute no columns.
  • Single quotes are doubled in strings. MySQL backslashes are doubled for the usual backslash-escape mode; NO_BACKSLASH_ESCAPES needs a separate review. PostgreSQL uses an E-prefixed literal when a backslash occurs. SQLite keeps backslashes literal.
  • This is SQL text, not bound parameters or schema validation. Review target types, constraints, permissions and session settings. Application writes should use driver or ORM parameters. JSON text does not automatically become a database JSON column.
  • JSON.parse uses JavaScript numbers: large integers can lose precision before conversion. Non-finite numbers, actual NUL characters and inputs with no columns are rejected. Use strings for identifiers that must retain every digit.
  • A primitive root maps to value; primitive array entries also get their original index. Top-level arrays become rows, not related tables. Empty input clears the result; an empty array produces only a comment. Conversion and downloads require JavaScript.

Frequently Asked Questions (FAQ)

Does JSON to SQL create a relational schema?▼

No. It generates one INSERT statement for one quoted table name. It does not infer CREATE TABLE, column types, keys, indexes or relations.

What happens when flattening creates duplicate column names?▼

user_name and user.name both map to user_name. Conversion stops with an error, even when the paths occur in different rows. Rename the keys or turn flattening off, then review the new mapping.

How do the three dialects handle quotes and backslashes?▼

String quotes are doubled. MySQL also doubles backslashes for its usual escape mode; PostgreSQL uses E literals for strings with backslashes; SQLite retains backslashes. Review the MySQL session mode before running a draft.

Can I use these INSERT statements as parameterized application writes?▼

The tool outputs literal SQL, with no placeholders or separate bound values. Use your database driver or ORM parameter API for application writes, and check database types and constraints yourself.