πŸ› οΈToolsShed

CSV ↔ JSON Converter

Convert CSV data to JSON and JSON arrays back to CSV format.

CSV to JSON Converter transforms spreadsheet-style comma-separated values into structured JSON objects, and vice versa. This conversion is a frequent step when moving data between APIs that return JSON and database exports or spreadsheets that use CSV format.

Paste your CSV data (with a header row) into the input field and the tool automatically maps each column name to a JSON key, producing an array of objects β€” one per row. For the reverse direction, paste a JSON array and receive clean, downloadable CSV output with headers derived from the object keys.

Options typically include choosing the delimiter (comma, semicolon, or tab), toggling whether strings should be quoted, and handling empty values. All conversion is done in the browser, making it safe for sensitive business data.

Frequently Asked Questions

Code Implementation

import csv
import json

# CSV string to JSON
csv_data = """name,age,city
Alice,30,London
Bob,25,Paris
Carol,35,Tokyo"""

reader = csv.DictReader(csv_data.splitlines())
result = list(reader)
print(json.dumps(result, indent=2))
# [{"name": "Alice", "age": "30", "city": "London"}, ...]

# CSV file to JSON
with open("data.csv", newline="", encoding="utf-8") as f:
    reader = csv.DictReader(f)
    rows = list(reader)

with open("data.json", "w", encoding="utf-8") as f:
    json.dump(rows, f, indent=2, ensure_ascii=False)

# JSON to CSV
data = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
with open("output.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=data[0].keys())
    writer.writeheader()
    writer.writerows(data)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.