Online JSON/CSV Converter: Convert Between JSON and Table Formats
What Is JSON/CSV Conversion
JSON/CSV conversion is the process of converting between JSON arrays (object lists) and CSV table format. JSON suits programmatic processing; CSV suits Excel and analytics tools. Convert between the two in one click with our JSON/CSV Converter.
Conversion Example
JSON → CSV:
[
{ "name": "Alice", "age": 28, "city": "Shanghai" },
{ "name": "Bob", "age": 32, "city": "Beijing" }
]
CSV Output:
name,age,city
Alice,28,Shanghai
Bob,32,Beijing
JSON vs CSV Use Cases
| Scenario | JSON | CSV | |----------|------|-----| | Web API | ✅ Preferred | ❌ Not suitable | | Excel processing | ❌ Not native | ✅ Native support | | Nested data | ✅ Supported | ❌ Not supported | | Data analysis | ⚠️ Needs parsing | ✅ Direct analysis | | Data export | ⚠️ Not intuitive | ✅ User-friendly | | Config files | ✅ Suitable | ❌ Not suitable | | Large datasets | ⚠️ Larger files | ✅ Smaller files |
Why You Need JSON/CSV Conversion
- Data analysis: Import API JSON data into Excel/Google Sheets
- Data export: Export database query results (JSON) as CSV downloads
- Data migration: Migrate data between different systems
- Report generation: Convert JSON data to CSV for reports
- Batch operations: Edit in Excel, export back to JSON
- Data visualization: Many tools accept CSV input
Conversion Challenges
Flattening Nested JSON
JSON supports nesting; CSV doesn't. You need to "flatten" nested objects:
// Original
{ "name": "Alice", "address": { "city": "Shanghai", "zip": "200000" } }
// Flattened
{ "name": "Alice", "address.city": "Shanghai", "address.zip": "200000" }
Array Field Handling
JSON arrays need special handling in CSV:
{ "name": "Alice", "tags": ["developer", "admin"] }
Common solutions: join with delimiter (developer;admin) or split into multiple rows.
How to Use an Online Tool
Using ToolVault's JSON/CSV Converter:
- Paste JSON array or CSV data
- The tool auto-detects format and converts
- Supports nested JSON flattening
- Custom delimiters and quote handling
- Preview and copy results
Conversion in Code
JavaScript: JSON to CSV
function jsonToCSV(jsonArray) {
if (!jsonArray.length) return '';
const flatten = (obj, prefix = '') =>
Object.entries(obj).reduce((acc, [key, val]) => {
const fullKey = prefix ? `${prefix}.${key}` : key;
if (typeof val === 'object' && val !== null && !Array.isArray(val)) {
Object.assign(acc, flatten(val, fullKey));
} else {
acc[fullKey] = Array.isArray(val) ? val.join(';') : val;
}
return acc;
}, {});
const flatData = jsonArray.map(item => flatten(item));
const headers = Object.keys(flatData[0]);
const rows = flatData.map(row =>
headers.map(h => {
const val = String(row[h] ?? '');
return val.includes(',') || val.includes('"') || val.includes('\n')
? `"${val.replace(/"/g, '""')}"` : val;
}).join(',')
);
return [headers.join(','), ...rows].join('\n');
}
JavaScript: CSV to JSON
function csvToJSON(csv) {
const lines = csv.trim().split('\n');
const headers = lines[0].split(',').map(h => h.trim());
return lines.slice(1).map(line => {
const values = line.split(',');
return headers.reduce((obj, header, i) => {
let val = values[i]?.trim() ?? '';
if (val === 'true') val = true;
else if (val === 'false') val = false;
else if (val === 'null') val = null;
else if (!isNaN(val) && val !== '') val = Number(val);
obj[header] = val;
return obj;
}, {});
});
}
FAQ
How to Convert Nested JSON to CSV?
You need to "flatten" nested objects first. Common approaches: dot notation (address.city) or underscore (address_city). Online tools typically handle flattening automatically.
Why Does CSV to JSON Lose Number Types?
CSV has no type info — all values are strings. Add type inference during conversion: detect numeric strings → Number, true/false → boolean.
How to Handle Nested Arrays in JSON?
JSON arrays can contain other arrays or objects. For CSV conversion, decide: flatten to multiple rows (one per element) or merge into one field (delimiter-separated). Depends on your use case.
This article is brought to you by ToolVault. More developer tools at the homepage.
Related Tools
Related Articles
JSON Troubleshooting Handbook: From Error Message to Fix (Symptom Index)
JSON errors that make no sense? This handbook organizes fixes by symptom — syntax errors, Unicode escaping, encoding mojibake, and Schema validation failures, with a diagnostic tree and a general debugging workflow.
JSON Schema Reports "required" Property Missing — How to Locate and Fix
JSON Schema validation says a required property is missing, or type mismatch? Explains required / additionalProperties / type pitfalls and how to locate the exact level with our validator.
JSON Shows Chinese as \uXXXX Escapes After Formatting — How to Get Readable Text Back
Why does formatted JSON turn Chinese into \uXXXX Unicode escapes, and how do you convert it back to readable text? Explains the cause and shows a one-click fix, all processed locally in your browser.