Skip to content
TypeParser
All tools

SQL Insert to JSON

Parse SQL INSERT statements to JSON.

beats codebeautify.org edge: Multi-row + column-aware
SQL INSERT
paste SQL
Guide

About SQL Insert to JSON

Read SQL <code>INSERT INTO ... VALUES (...)</code> statements and produce a JSON array of objects matching the column list. Handles multi-row inserts, NULL, escaped strings, numeric literals, date strings. Useful when you have a SQL dump and want JSON for fixtures or analysis.

Working with JSON inside SQL

This tool covers the offline path — turning a SQL INSERT dump into JSON. If instead you want to read or emit JSON from a live database, use the native functions:

  • SQL Server (JSON support added in 2016): SELECT ... FOR JSON PATH builds JSON from rows; OPENJSON(@json) shreds JSON into rows; JSON_VALUE(col, '$.key') extracts a scalar. To build a table from JSON: SELECT * INTO t FROM OPENJSON(@json) WITH (id int, name nvarchar(100)).
  • PostgreSQL: store as jsonb, query with ->/->>, build with row_to_json() and json_agg().
  • MySQL: the JSON type plus JSON_EXTRACT() / ->>.
  • Escaping: in SQL Server JSON paths, a key containing ] or other reserved characters must be wrapped in double quotes — $."weird]key".

For the reverse (JSON → SQL) at scale, prefer the database’s own bulk importer (bcp, COPY, LOAD DATA) over generated INSERT statements.

Common workflow this solves

You have a SQL dump from a teammate. You want JSON to load into your dev environment, or to feed into a fixture, or to inspect in a tool that does not speak SQL. Cleaner than spinning up a database just to extract rows.

How parsing works

  1. Tokenize the SQL.
  2. Find each INSERT INTO.
  3. Pull the column list from the parens after the table name.
  4. Parse the VALUES list — each tuple becomes one object.
  5. Coerce literals: numbers, strings, booleans, NULL, dates per setting.

The output is one JSON array per input statement, or a single combined array if all statements target the same table.

What it can’t do

  • INSERT ... SELECT — needs query execution, not just parsing.
  • Vendor-specific syntax — Oracle INSERT ALL, MS SQL stored procedures, Postgres RETURNING. Strip these before pasting.
  • Computed columns — defaults, sequences, triggers. The output reflects the literal values.
  • JSON columns — content stays as strings; pass through JSON Formatter to nest.

Common workflows

Fixture from production. Coworker dumps a row’s SQL. Paste, convert, drop into your test fixture file.

Migrate from SQL to NoSQL. Dump table contents, convert, ingest into MongoDB / DynamoDB / Firestore. Skip the round-trip through a real ETL.

Inspect a tabular dump in JSON tooling. Easier to grep, filter, and reshape JSON than SQL with a text editor.

Frequently asked questions

What syntax is supported?
Standard INSERT INTO table (col1, col2) VALUES (v1, v2), (v3, v4). Both single-row and multi-row. MySQL, Postgres, SQLite syntax all work; Oracle's INSERT ALL needs preprocessing.
What about escaped quotes?
Both 'O''Brien' (SQL doubled-quote) and 'O\'Brien' (backslash-escape) parse correctly.
How are NULL values rendered?
JSON null. Distinguished from the string 'NULL'.
Numeric literals?
Plain 123 becomes a JSON number; quoted '123' stays a string. Decimals likewise — adjust with the type-coercion toggle if your schema disagrees.
Dates and timestamps?
Stay as strings (ISO 8601 if that is what your SQL uses). Date detection is opt-in.
Can it process a big SQL dump?
Up to a few MB cleanly. For multi-GB dumps, stream through a proper parser like mysqldump-to-json.
How do I query, store, or parse JSON inside SQL itself?
SQL Server (JSON support since 2016): return rows as JSON with SELECT ... FOR JSON PATH, and read JSON into rows with OPENJSON(@json); extract a value with JSON_VALUE(col, '$.key'). PostgreSQL: use jsonb columns and the -> / ->> operators, or row_to_json() / json_agg() to build JSON. MySQL: the JSON type plus JSON_EXTRACT(). This tool handles the offline direction — turning an INSERT dump into JSON without a running database.
How do I convert JSON back to SQL, or build a table from JSON?
To go JSON → SQL, generate CREATE TABLE + INSERT statements from the keys of your array: each object key becomes a column, each object a row. In SQL Server, SELECT * INTO newtable FROM OPENJSON(@json) WITH (...) creates and fills a table in one shot. Paste your JSON into a generator or use the database's native importer for large sets.

Related tools

Last updated: 2026-07-04