SQL to JSON Converter

Transform SQL database dumps into JSON format for web development, APIs, and NoSQL databases

SQL Input

JSON Output

About SQL to JSON Converter

Convert SQL database dumps (CREATE TABLE and INSERT statements) to JSON format with automatic type detection. Perfect for web development, REST APIs, NoSQL databases, and JavaScript applications. Supports both Array of Objects and Array of Arrays formats.

Key Features

  • Automatic Type Detection: Converts numbers, booleans, and null values automatically
  • Array of Objects: Use column names as object keys for structured data
  • Array of Arrays: Simple nested array format for compact representation
  • Pretty Print: Optional formatting with indentation for readability
  • Minified Output: Compact JSON without whitespace for production use
  • RFC 8259 Compliant: Standard JSON format compatible with all parsers
  • File Download: Save as .json file

How to Use

  1. Input SQL Data: Paste your SQL CREATE TABLE and INSERT statements or upload a .sql file
  2. Choose Format: Select Array of Objects or Array of Arrays format
  3. Configure Output: Toggle pretty print for formatted or minified output
  4. Copy or Download: Use the Copy or Download button to save your JSON

Output Formats

Array of Objects (with headers):

[
  {
    "id": 1,
    "name": "Laptop",
    "price": 999.99,
    "available": true
  },
  {
    "id": 2,
    "name": "Mouse",
    "price": 24.99,
    "available": true
  }
]

Array of Arrays:

[
  ["id", "name", "price", "available"],
  [1, "Laptop", 999.99, true],
  [2, "Mouse", 24.99, true]
]

Type Detection

  • Numbers: Automatically converts numeric strings to numbers (123, 45.67)
  • Booleans: Converts 'true' and 'false' strings to boolean values
  • Null: Converts 'NULL' and empty strings to null
  • Strings: All other values remain as strings

Example Conversion

SQL Input:

CREATE TABLE products (
  id INT,
  name VARCHAR(100),
  price DECIMAL(10,2),
  available BOOLEAN
);

INSERT INTO products VALUES (1, 'Laptop', 999.99, true);
INSERT INTO products VALUES (2, 'Mouse', 24.99, false);

JSON Output (Array of Objects, Pretty Print):

[
  {
    "id": 1,
    "name": "Laptop",
    "price": 999.99,
    "available": true
  },
  {
    "id": 2,
    "name": "Mouse",
    "price": 24.99,
    "available": false
  }
]

JSON Output (Minified):

[{"id":1,"name":"Laptop","price":999.99,"available":true},{"id":2,"name":"Mouse","price":24.99,"available":false}]

Common Use Cases

  • Web Development: Convert database data for frontend JavaScript applications
  • REST APIs: Generate JSON responses for API endpoints
  • NoSQL Migration: Import SQL data into MongoDB, CouchDB, or Firebase
  • Data Exchange: Share database data in a platform-independent format
  • Testing: Create test fixtures and mock data for unit tests
  • Configuration: Convert database configurations to JSON files

When to Use Each Format

Array of Objects:

  • Best for most web applications and APIs
  • Self-documenting with named properties
  • Easy to work with in JavaScript/TypeScript
  • Recommended for JSON APIs and frontend data

Array of Arrays:

  • More compact representation
  • Smaller file size for large datasets
  • Good for data processing and analytics
  • Compatible with CSV-like data structures

Pretty Print vs. Minified

Pretty Print (Formatted):

  • Human-readable with indentation and line breaks
  • Easy to debug and inspect
  • Recommended for development and documentation
  • Larger file size due to whitespace

Minified (Compact):

  • No whitespace or formatting
  • Smaller file size for production use
  • Faster parsing and network transfer
  • Recommended for APIs and production data

Supported SQL Syntax

  • CREATE TABLE: Extracts column names for JSON object keys
  • INSERT INTO: Parses data values from INSERT statements
  • Data Types: Handles all SQL data types (VARCHAR, INT, DECIMAL, BOOLEAN, etc.)
  • Quoted Strings: Handles single and double quotes with proper escaping
  • NULL Values: Converts NULL to JSON null

JSON Standards

  • RFC 8259: Compliant with official JSON specification
  • UTF-8 Encoding: Supports all Unicode characters
  • Escape Sequences: Properly escapes special characters
  • Number Format: Uses standard JSON number representation

Integration Examples

JavaScript/TypeScript:

const data = JSON.parse(jsonOutput);
data.forEach(item => {
  console.log(item.name, item.price);
});

MongoDB Import:

mongoimport --db mydb --collection products --file output.json --jsonArray

Fetch API:

fetch('/api/products')
  .then(res => res.json())
  .then(data => console.log(data));

Privacy & Security

All conversions happen locally in your browser. Your SQL data is never uploaded to any server, ensuring complete privacy and security.