ModernCalcs

SQL INSERT to JSON

[
  {
    "id": 1,
    "name": "Alice Smith",
    "email": "alice@example.com",
    "active": true
  },
  {
    "id": 2,
    "name": "Bob Jones",
    "email": "bob@example.com",
    "active": false
  },
  {
    "id": 3,
    "name": "Charlie Brown",
    "email": "charlie@example.com",
    "active": null
  }
]

Parses a single INSERT INTO statement with multiple value rows. Typed: NULL → null, TRUE/FALSE → boolean, numbers stay numeric. Quoted strings are unescaped.

SQL INSERT to JSON: Convert Database Seed Data to API-Ready Format

SQL INSERT statements are the standard way to seed databases and export rows, but they're not directly usable by APIs or JavaScript tooling that expects JSON. This converter parses an INSERT INTO statement — extracting column names and values — and produces a typed JSON array where nulls, booleans, and numbers keep their proper types.

Formula
INSERT INTO users (id, name, active) VALUES (1, 'Alice', TRUE), (2, 'Bob', FALSE), (3, 'Charlie', NULL); → JSON: [ { "id": 1, "name": "Alice", "active": true }, { "id": 2, "name": "Bob", "active": false }, { "id": 3, "name": "Charlie", "active": null } ]

Column names from the INSERT become JSON keys. Types are preserved: numbers, booleans, and null map to their JSON equivalents.

Why Convert SQL INSERT to JSON?

SQL INSERT statements are used in database migrations, seed scripts, and SQL dump files. When you need to feed this data to a REST API, use it in JavaScript fixtures, or import it into a NoSQL database like MongoDB or Firestore, JSON is the required format. Converting manually is tedious and error-prone for multi-row inserts.

Type Mapping: SQL to JSON

NULL → JSON null. TRUE/FALSE (case-insensitive) → JSON boolean true/false. Unquoted integers → JSON integer. Unquoted decimals → JSON float. Single-quoted strings → JSON string (SQL's '' escaped quote becomes a single '). Date strings like '2021-01-01' remain quoted strings in JSON. Functions like NOW() or UUID() are left as-is as strings.

Handling Large Inserts

Modern SQL dumps use multi-row INSERT statements to batch thousands of rows in one statement: INSERT INTO table (cols) VALUES (row1), (row2), ..., (rowN). This converter handles any number of value groups in a single INSERT, producing a JSON array with one object per row. For very large dumps, convert section by section.

Practical Examples

Converting a MySQL Dump Snippet

Extract row data from a mysqldump output for use in a REST API.

  • 1.Open the .sql dump file and find the INSERT INTO statement
  • 2.Copy the INSERT statement (just one table at a time)
  • 3.Paste here — the JSON array shows every row as an object
  • 4.Use the JSON in your API client, test fixture, or seed script

SQL Features Handled

  • Multiple value rows: VALUES (r1), (r2), (r3)
  • NULL → JSON null
  • TRUE/FALSE → JSON boolean
  • Numbers: integer and decimal
  • Single-quoted strings with '' escape
  • Backtick/bracket/double-quoted column names

Frequently Asked Questions

What SQL INSERT syntax is supported?

The converter supports the standard INSERT INTO table_name (col1, col2, ...) VALUES (val1, val2, ...), (val3, val4, ...) syntax. The column list is required — INSERT INTO table VALUES (...) without column names is not supported because column order cannot be inferred. Multiple value tuples in a single INSERT are fully supported.

How are SQL types mapped to JSON types?

NULL → JSON null. TRUE/FALSE → JSON boolean. Unquoted integers and decimals → JSON number. Single-quoted strings → JSON string (with SQL's '' escape unescaped to '). Everything else → JSON string as-is. This means 42 stays 42 as a number in JSON, while '42' becomes the string "42".

Can I convert multiple INSERT statements?

This tool parses a single INSERT statement at a time. If you have multiple INSERT statements for the same table, combine their value rows into one statement: INSERT INTO table (cols) VALUES (row1), (row2), (row3). For multiple different tables, convert each statement separately.

What about backtick and bracket-quoted identifiers?

MySQL uses backtick-quoted column names (\`column\`), SQL Server uses bracket-quoted names ([column]), and PostgreSQL uses double-quoted names ("column"). All three quoting styles are stripped when extracting column names, so the resulting JSON keys are plain identifiers.