SQL to JSON Converter
Convert SQL INSERT statements to JSON arrays. Paste your SQL:
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 Value | JSON Result |
|---|---|
'text' or "text" | "text" |
123 | 123 |
45.67 | 45.67 |
TRUE / FALSE | true / false |
NULL | null |
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
- JSON to SQL โ Convert JSON back to SQL
- JSON Validator โ Validate the output
- JSON to CSV โ Export as spreadsheet
- CSV to JSON โ Alternative data import
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.