Examples
Practical examples demonstrating various use cases for the JSON to CSV converter.
Basic Examples
Simple Array Conversion
Input JSON:
[
{ "name": "Alice", "age": 28, "city": "New York" },
{ "name": "Bob", "age": 32, "city": "Los Angeles" },
{ "name": "Charlie", "age": 25, "city": "Chicago" }
]
Output CSV:
name,age,city
Alice,28,New York
Bob,32,Los Angeles
Charlie,25,Chicago
Single Object Conversion
Input JSON:
{
"product": "Laptop",
"price": 1299.99,
"category": "Electronics",
"inStock": true,
"tags": ["portable", "gaming", "work"]
}
Output CSV:
product,price,category,inStock,tags
Laptop,1299.99,Electronics,true,"[""portable"",""gaming"",""work""]"
Real-World Examples
E-commerce Product Data
Input JSON (Product catalog):
[
{
"id": "P001",
"name": "Wireless Headphones",
"brand": "TechSound",
"price": 199.99,
"currency": "USD",
"availability": {
"inStock": true,
"quantity": 150
},
"specifications": {
"battery": "20 hours",
"connectivity": "Bluetooth 5.0",
"weight": "250g"
},
"reviews": {
"average": 4.5,
"count": 128
}
},
{
"id": "P002",
"name": "Smart Watch",
"brand": "FitTech",
"price": 299.99,
"currency": "USD",
"availability": {
"inStock": false,
"quantity": 0
},
"specifications": {
"battery": "7 days",
"connectivity": "Bluetooth, WiFi",
"weight": "45g"
},
"reviews": {
"average": 4.2,
"count": 89
}
}
]
Output CSV (Flattened):
id,name,brand,price,currency,availability.inStock,availability.quantity,specifications.battery,specifications.connectivity,specifications.weight,reviews.average,reviews.count
P001,Wireless Headphones,TechSound,199.99,USD,true,150,20 hours,Bluetooth 5.0,250g,4.5,128
P002,Smart Watch,FitTech,299.99,USD,false,0,7 days,"Bluetooth, WiFi",45g,4.2,89
API Response Data
Input JSON (User management API):
{
"users": [
{
"id": 1,
"username": "john_doe",
"email": "john@example.com",
"profile": {
"firstName": "John",
"lastName": "Doe",
"avatar": "https://example.com/avatars/john.jpg"
},
"permissions": ["read", "write"],
"lastLogin": "2024-01-15T10:30:00Z",
"active": true
},
{
"id": 2,
"username": "jane_smith",
"email": "jane@example.com",
"profile": {
"firstName": "Jane",
"lastName": "Smith",
"avatar": "https://example.com/avatars/jane.jpg"
},
"permissions": ["read"],
"lastLogin": "2024-01-14T15:45:00Z",
"active": true
}
],
"total": 2,
"page": 1,
"limit": 10
}
Output CSV (Users array only):
id,username,email,profile.firstName,profile.lastName,profile.avatar,permissions,lastLogin,active
1,john_doe,john@example.com,John,Doe,https://example.com/avatars/john.jpg,"[""read"",""write""]",2024-01-15T10:30:00Z,true
2,jane_smith,jane@example.com,Jane,Smith,https://example.com/avatars/jane.jpg,"[""read""]",2024-01-14T15:45:00Z,true
Advanced Examples
Financial Data
Input JSON (Stock market data):
[
{
"symbol": "AAPL",
"company": "Apple Inc.",
"sector": "Technology",
"price": {
"current": 175.43,
"open": 174.2,
"high": 176.15,
"low": 173.5,
"previousClose": 174.2
},
"volume": 45678900,
"marketCap": 2750000000000,
"dividend": {
"yield": 0.0044,
"amount": 0.24,
"frequency": "quarterly"
},
"analysts": {
"rating": "Buy",
"targetPrice": 185.0,
"recommendations": {
"strongBuy": 12,
"buy": 8,
"hold": 3,
"sell": 1,
"strongSell": 0
}
}
}
]
Output CSV:
symbol,company,sector,price.current,price.open,price.high,price.low,price.previousClose,volume,marketCap,dividend.yield,dividend.amount,dividend.frequency,analysts.rating,analysts.targetPrice,analysts.recommendations
AAPL,Apple Inc.,Technology,175.43,174.20,176.15,173.50,174.20,45678900,2750000000000,0.0044,0.24,quarterly,Buy,185.00,"{""strongBuy"":12,""buy"":8,""hold"":3,""sell"":1,""strongSell"":0}"
Survey Data
Input JSON (Customer satisfaction survey):
[
{
"respondentId": "R001",
"timestamp": "2024-01-15T14:30:00Z",
"demographics": {
"age": "25-34",
"gender": "Female",
"location": "California"
},
"responses": {
"satisfaction": 4,
"recommendation": 5,
"comments": "Great product, excellent customer service!"
},
"metadata": {
"surveyVersion": "v2.1",
"completionTime": 180,
"device": "mobile"
}
},
{
"respondentId": "R002",
"timestamp": "2024-01-15T16:45:00Z",
"demographics": {
"age": "35-44",
"gender": "Male",
"location": "Texas"
},
"responses": {
"satisfaction": 3,
"recommendation": 3,
"comments": "Product is okay, but could be better."
},
"metadata": {
"surveyVersion": "v2.1",
"completionTime": 120,
"device": "desktop"
}
}
]
Output CSV:
respondentId,timestamp,demographics.age,demographics.gender,demographics.location,responses.satisfaction,responses.recommendation,responses.comments,metadata.surveyVersion,metadata.completionTime,metadata.device
R001,2024-01-15T14:30:00Z,25-34,Female,California,4,5,"Great product, excellent customer service!",v2.1,180,mobile
R002,2024-01-15T16:45:00Z,35-44,Male,Texas,3,3,"Product is okay, but could be better.",v2.1,120,desktop
Special Character Handling
International Data
Input JSON (Multilingual content):
[
{
"id": 1,
"title": "Café & Restaurant",
"description": "Un café français avec une cuisine délicieuse",
"location": "Paris, France",
"specialChars": "Café, naïve, résumé, piñata, 北京, 東京"
},
{
"id": 2,
"title": "北京烤鸭店",
"description": "正宗北京烤鸭,传统工艺制作",
"location": "北京, 中国",
"specialChars": "中文,English,Français,Español"
}
]
Output CSV (UTF-8 encoding):
id,title,description,location,specialChars
1,Café & Restaurant,Un café français avec une cuisine délicieuse,Paris France,Café naïve résumé piñata 北京 東京
2,北京烤鸭店,正宗北京烤鸭传统工艺制作,北京 中国,中文EnglishFrançaisEspañol
Data with Quotes and Commas
Input JSON:
[
{
"name": "Smith, John",
"quote": "He said \"Hello, World!\" to everyone",
"description": "A person who likes to say \"Hello\" and \"Goodbye\"",
"address": "123 Main St, Apt 4B, New York, NY 10001"
}
]
Output CSV (With quote escaping):
name,quote,description,address
"Smith, John","He said ""Hello, World!"" to everyone","A person who likes to say ""Hello"" and ""Goodbye""","123 Main St, Apt 4B, New York, NY 10001"
Configuration Examples
European CSV Format
Settings:
- Delimiter: Semicolon (;)
- Encoding: UTF-8
- Include Headers: Yes
- Escape Quotes: Yes
Input JSON:
[
{ "name": "Müller", "city": "München", "price": "1.234,56" },
{ "name": "Schmidt", "city": "Köln", "price": "2.345,67" }
]
Output CSV:
name;city;price
Müller;München;1.234,56
Schmidt;Köln;2.345,67
Tab-Separated Values (TSV)
Settings:
- Delimiter: Tab
- Encoding: UTF-8
- Include Headers: Yes
- Escape Quotes: No
Input JSON:
[
{ "gene": "BRCA1", "mutation": "c.5266dupC", "significance": "Pathogenic" },
{ "gene": "TP53", "mutation": "c.742C>T", "significance": "Likely Pathogenic" }
]
Output TSV:
gene mutation significance
BRCA1 c.5266dupC Pathogenic
TP53 c.742C>T Likely Pathogenic
Error Handling Examples
Invalid JSON Input
Input (Missing comma):
[
{"name": "John" "age": 30}
]
Error Output:
Invalid JSON format. Please check your input.
Empty Data
Input:
[]
Output:
(Empty CSV - no data to convert)
Mixed Data Types
Input JSON:
[
{ "id": 1, "name": "Product A", "active": true, "price": 99.99, "tags": null },
{ "id": 2, "name": "Product B", "active": false, "price": 149.99, "tags": ["electronics"] },
{ "id": 3, "name": "Product C", "active": true, "price": null, "tags": ["gadget", "portable"] }
]
Output CSV:
id,name,active,price,tags
1,Product A,true,99.99,
2,Product B,false,149.99,"[""electronics""]"
3,Product C,true,,"[""gadget"",""portable""]"
Performance Examples
Large Dataset
Input JSON (1000 records):
[
// ... 1000 user records
{
"id": 1,
"name": "User 1",
"email": "user1@example.com",
"department": "Engineering",
"salary": 75000,
"hireDate": "2020-01-15"
}
// ... 999 more records
]
Processing Time: ~50ms for 1000 records Output Size: ~150KB CSV file Memory Usage: ~2MB during processing
Memory Optimization
For very large datasets, consider processing in chunks:
// Process 10,000 records in chunks of 1000
const chunkSize = 1000;
const chunks = [];
for (let i = 0; i < largeDataset.length; i += chunkSize) {
chunks.push(largeDataset.slice(i, i + chunkSize));
}
// Process each chunk
chunks.forEach((chunk, index) => {
const csv = jsonToCSV(chunk);
downloadCSV(csv, `data_chunk_${index + 1}.csv`);
});