{}JSONLint.app

SQL to JSON Converter

Convert SQL INSERT statements to JSON arrays. Paste your SQL:

Loading...
Loading...
💡 Tip: Paste SQL INSERT statements. Column names are extracted from the INSERT clause or CREATE TABLE if present.

Convert SQL to JSON

This tool extracts data from SQL INSERT statements and converts it to JSON format. It parses column names and values, handling strings, numbers, booleans, and NULL values.

Supported SQL Syntax

The converter handles:

  • INSERT INTO with explicit column names
  • Multiple value sets in single INSERT
  • Multiple INSERT statements
  • CREATE TABLE for column name extraction
  • Standard SQL value types (strings, numbers, booleans, NULL)

Example Conversion

Input SQL:

INSERT INTO users (id, name, active) VALUES
  (1, 'Alice', TRUE),
  (2, 'Bob', FALSE);

Output JSON:

[
  { "id": 1, "name": "Alice", "active": true },
  { "id": 2, "name": "Bob", "active": false }
]

Type Conversion

SQL ValueJSON Result
'text' or "text""text"
123123
45.6745.67
TRUE / FALSEtrue / false
NULLnull

Common Use Cases

  • Database exports — Convert SQL dumps to JSON for analysis
  • API migration — Transform database data for REST APIs
  • Testing — Generate JSON fixtures from SQL test data
  • Documentation — Convert sample data to readable JSON

Handling Edge Cases

Escaped quotes

Single quotes within strings should be escaped as '' (standard SQL escaping):

INSERT INTO messages (text) VALUES ('It''s working');
-- Becomes: { "text": "It's working" }

Multiple tables

If your SQL contains inserts to multiple tables, all rows are combined. For best results, convert one table at a time.

Programmatic Conversion

Python

import re
import json

def sql_insert_to_json(sql):
    # Simple regex for INSERT VALUES
    pattern = r"INSERT INTO w+ (([^)]+)) VALUES (.+)"
    match = re.search(pattern, sql, re.IGNORECASE)
    
    columns = [c.strip() for c in match.group(1).split(',')]
    # Parse values and build objects...
    return json.dumps(result, indent=2)

JavaScript

// Using a SQL parser library
import { Parser } from 'node-sql-parser';

const parser = new Parser();
const ast = parser.astify(sql);
// Extract data from AST...

Related Tools

Frequently Asked Questions

Can I convert SELECT query results?

This tool parses INSERT statements, not query results. For SELECT output, export as CSV first, then use our CSV to JSON converter.

What SQL dialects are supported?

The parser handles standard SQL syntax compatible with MySQL, PostgreSQL, SQLite, and SQL Server. Dialect-specific features may not be supported.

How do I handle large SQL files?

The tool runs in your browser, so very large files may be slow. For massive datasets, consider using command-line tools or programming libraries.

Common Mistakes & Pro Tips

  • Column names come from the INSERT's column listJSON keys are taken from the (col1, col2, ...) list in INSERT INTO table (col1, col2) VALUES (...). If that list is omitted, the converter can only fall back to positional keys like "column_1" because the column names live in the table definition, not the statement.
  • SQL NULL is not the string 'NULL'An unquoted NULL token must become JSON null, while the quoted literal 'NULL' is the text "NULL". Mixing these up is a common bug, so confirm that bare NULL in your VALUES list maps to null and only quoted values become strings.
  • Escaped quotes inside string valuesIn standard SQL a single quote inside a string is escaped by doubling it ('O''Brien'), while some dumps (notably MySQL) use a backslash (\'). The parser must unescape these back to one quote — O'Brien — rather than leaving the doubled or backslashed form in the JSON.
  • Numbers, booleans, and dates are dialect-dependentUnquoted numerics like 42 or 3.14 become JSON numbers, but booleans vary: some databases use TRUE/FALSE, others 0/1, and dates are usually quoted strings like '2024-01-01'. Don't assume a column is a real boolean or date type just from the literal.
  • Multi-row INSERTs and trailing semicolonsA single INSERT can list many VALUES (...) tuples separated by commas, each becoming one object, and statements end with a semicolon. Comments (-- or /* */) and other DDL/DML around the inserts are ignored, so only the INSERT data is extracted.

Frequently Asked Questions

How do I convert SQL INSERT statements to JSON?

Paste one or more INSERT INTO ... VALUES statements; the parser reads the column list for keys and each VALUES tuple for a row, producing an array of objects. Multi-row inserts yield multiple objects. Surrounding statements like CREATE TABLE are ignored, so a full dump still works.

What happens to NULL values?

A bare, unquoted NULL in the VALUES list is converted to JSON null, correctly representing the absence of a value. A quoted 'NULL' is treated as the literal four-character string "NULL" instead, so quoting matters.

How are quoted strings with apostrophes handled?

SQL escapes an embedded single quote by doubling it, so 'It''s' is unescaped to "It's" in the JSON. Backslash-escaped quotes from MySQL-style dumps (\') are also normalized to a single quote. The surrounding delimiting quotes are removed.

Does it work if my INSERT has no column list?

It can still split each row into values, but without the (col1, col2, ...) list it cannot know the real column names, so it assigns generic positional keys. To get meaningful keys, include the column list in the INSERT or add it manually.

Will numbers become JSON numbers or strings?

Unquoted numeric literals such as 100 or 9.99 are emitted as JSON numbers, while anything inside single quotes is kept as a string. Be careful with very large integer IDs, since JSON numbers lose precision beyond 9007199254740991 — keep those as strings if exactness matters.

Is my SQL processed in the browser?

Yes. The statements are parsed locally with JavaScript and never uploaded, so production data and schema details stay on your machine. This is useful when extracting seed data from a dump you can't share externally.