Data Converter
CSV ↔ JSON ↔ SQL Converter
Convert data between CSV, JSON arrays, and SQL INSERT queries instantly. Delimiter auto-detection, null handling, and zero data uploads.
100% Client-Side — Data processed locally
Developer Reference
Core Algorithm & Standalone Script
Standalone, zero-dependency JavaScript functions for parsing CSV, converting JSON arrays, and generating SQL INSERT statements.
// Standalone CSV ↔ JSON ↔ SQL Converter (Vanilla JS)
function csvToJson(csvText) {
const lines = csvText.split(/\r?\n/).filter(l => l.trim());
if (lines.length === 0) return [];
const headers = lines[0].split(',').map(h => h.trim().replace(/^"|"$/g, ''));
const data = [];
for (let i = 1; i < lines.length; i++) {
const cells = lines[i].split(',').map(c => c.trim().replace(/^"|"$/g, ''));
const obj = {};
headers.forEach((h, idx) => {
let val = cells[idx] !== undefined ? cells[idx] : '';
if (val.toLowerCase() === 'true') val = true;
else if (val.toLowerCase() === 'false') val = false;
else if (val !== '' && !isNaN(val)) val = Number(val);
obj[h || `col_\${idx + 1}`] = val;
});
data.push(obj);
}
return data;
}
function jsonToSql(jsonArray, tableName = 'my_table') {
if (!Array.isArray(jsonArray) || jsonArray.length === 0) return '';
const cols = Object.keys(jsonArray[0]).map(c => `\`\${c}\``).join(', ');
return jsonArray.map(row => {
const vals = Object.values(row).map(v => {
if (v === null || v === undefined) return 'NULL';
if (typeof v === 'number') return v;
if (typeof v === 'boolean') return v ? 'TRUE' : 'FALSE';
return `'${String(v).replace(/'/g, "''")}'`;
}).join(', ');
return `INSERT INTO \`\${tableName}\` (\${cols}) VALUES (\${vals});`;
}).join('\n');
}