Convert SQL query results to JSON format
Convert SQL query results to JSON format instantly with our free online SQL to JSON converter. This tool helps developers and database administrators transform SQL data into JSON for APIs and web applications. Simply paste your SQL results and get JSON output in real-time.
Convert SQL query result tables to JSON format. Supports multiple input formats.
Supported formats:
id | name | ageid,name,ageFeatures:
SQL to JSON converter transforms SQL query results or CREATE TABLE statements into JSON format. Essential for API development, data migration, database documentation, and bridging relational databases with NoSQL or JavaScript applications.
For query results: each row becomes a JSON object with column names as keys. For CREATE TABLE: extracts table name, columns, types, and constraints into structured JSON. Handles NULL values, data types, and nested structures appropriately.
SQL types map to JSON: VARCHAR/TEXT → string, INT/BIGINT → number, BOOLEAN → true/false, NULL → null, DATE/TIMESTAMP → ISO string. Arrays and JSON columns may need special handling. Preserves column order from SELECT or table definition.
Convert database results to JSON for REST APIs.
Export schema as JSON for documentation tools.
Convert relational data to document format for NoSQL.
Generate JSON fixtures from SQL queries.
// Database query result to JSON
function sqlResultToJSON(columns, rows) {
return rows.map(row => {
const obj = {};
columns.forEach((col, i) => {
obj[col.name] = row[i];
});
return obj;
});
}
// Example usage
const columns = [{name: 'id'}, {name: 'name'}, {name: 'email'}];
const rows = [
[1, 'John', 'john@example.com'],
[2, 'Jane', 'jane@example.com']
];
JSON.stringify(sqlResultToJSON(columns, rows), null, 2);
// [
// {"id": 1, "name": "John", "email": "john@example.com"},
// {"id": 2, "name": "Jane", "email": "jane@example.com"}
// ]Map each row to an object using column names as keys. Handle nulls and type conversion as needed.
Use SQL to JSON when building APIs that query databases, migrating data to document stores, generating test fixtures, or creating database documentation.
NULL becomes JSON null. Some converters offer options: omit null fields, use empty string, or use a sentinel value. JSON null is usually the correct choice for data integrity.