SQL to JSON

Turn INSERT statements into JSON rows for fixtures, seeds and tests.

Database Runs in your browser
INSERT statements
JSON

Nothing converted yet

Paste INSERT statements to get a JSON array of rows, with numbers, booleans and NULL typed correctly.

Runs entirely in your browser. Your data isn't uploaded — this page makes no network request with anything you type, which you can verify in your browser's network tab. How this works.

What is the SQL to JSON?

Test fixtures, seed data and API mocks are often derived from SQL that already exists — a dump, a set of INSERT statements from a migration, or rows exported from a staging database. Converting them by hand is tedious and error-prone.

Paste INSERT statements here and get a JSON array of row objects, with column names as keys and values typed sensibly: numbers stay numbers, NULL becomes null, and booleans are recognised. CREATE TABLE statements can be converted into a JSON Schema sketch instead.

How to use it

  1. Paste one or more INSERT statements, including the column list.
  2. Press Convert (or Ctrl/Cmd + Enter).
  3. Choose whether to group rows by table when the input covers several.
  4. Copy the JSON, or download it as a fixture file.

Example

A multi-row INSERT turned into fixture data.

Input
INSERT INTO regions (code, name, active) VALUES ('eu-west-1','Ireland',true),('ap-southeast-1','Singapore',false);
Result
[
  { "code": "eu-west-1", "name": "Ireland", "active": true },
  { "code": "ap-southeast-1", "name": "Singapore", "active": false }
]

Features

  • Multi-row and multi-statement INSERT support
  • Type inference for integers, decimals, booleans and NULL
  • Correct handling of escaped quotes inside string literals
  • Optional grouping by table name
  • CREATE TABLE to JSON Schema sketch mode

Frequently asked questions

What if my INSERT has no column list?
Values are emitted as a positional array instead of an object, since there are no names to key on. Supply a column list, or paste the matching CREATE TABLE, to get objects.
Does it run the SQL?
No. Nothing is executed and there is no database involved — the statements are parsed as text in your browser.
Can it convert a SELECT query result?
Not from the query itself, since that would require running it. Export the result as INSERT statements or CSV and convert that.
Esc

Loading the catalog…