What does the CSV Formatter & Beautifier do?
The CSV Formatter & Beautifier cleans messy CSV spreadsheet rows, trims whitespace around cell values, normalizes column counts across all rows, converts delimiters (comma, tab TSV, semicolon, pipe), applies customizable quote policies, and generates monospaced ASCII grid tables.
Core Concepts
Understanding CSV formatting rules and RFC 4180 specifications:
- Delimiter Conversion: Automatically detects input separators (comma, tab, semicolon, pipe) and reformats rows into your chosen output delimiter.
- Quote Policies:
- As Needed: Encloses cells in quotes only if they contain delimiters, double quotes, or newline breaks.
- All: Encloses every cell value in quotes.
- None: Strips all quotation marks from cell values.
- ASCII Table Generation: Generates monospace-padded text tables with aligned vertical borders and header dividers for Markdown documents or terminal output.
How to use the tool?
- Paste CSV Data: Enter or paste your unformatted CSV/TSV spreadsheet data into the editor or click Load Sample.
- Configure Settings:
- Choose your desired Output Delimiter (Comma, Tab TSV, Semicolon, Pipe).
- Select your preferred Quote Policy (As Needed, Quote All, No Quotes).
- Choose your Output Format (CSV Data or Monospace ASCII Grid Table).
- Format & Export: Click Format & Beautify CSV, then click Copy or Download to save your formatted spreadsheet table.
Related Developer Utilities
If you work with spreadsheet data, tabular conversions, and delimiter manipulation, explore these complementary tools:
- CSV to JSON Converter: Convert tabular CSV and TSV datasets into structured JSON objects.
- JSON Formatter & Beautifier: Format and prettify raw JSON payloads.
- JSON to CSV Converter: Flatten nested JSON arrays into tabular CSV rows.
- YAML to CSV Converter: Transform YAML list documents into tabular CSV spreadsheets.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-formatter) to programmatically format, normalize cell padding, convert delimiters, and generate ASCII grid tables from CSV spreadsheet data.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
payload |
String or Array | The raw CSV string payload OR a native JavaScript array-of-arrays to format and beautify. Aliases: rawText, text, input, csv. |
" id , name \n 1 , Alice " |
options |
Object | Optional settings (outputDelimiter, quotePolicy, formatStyle). |
{"outputDelimiter": ",", "formatStyle": "csv"} |
API Request Payload Examples
cURL (String Payload)
curl -X POST https://blueutils.com/api/csv/csv-formatter \
-H "Content-Type: application/json" \
-d '{
"payload": " id , name , role \n 1 , Alice , Dev ",
"options": { "outputDelimiter": ",", "formatStyle": "csv" }
}'Python (Array Payload)
import requests
url = "https://blueutils.com/api/csv/csv-formatter"
payload = {
"payload": [["id", "name", "role"], ["1", "Alice", "Dev"]],
"options": { "outputDelimiter": ",", "formatStyle": "csv" }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"payload": " id , name , role \\n 1 , Alice , Dev ",
"options": {
"outputDelimiter": ",",
"formatStyle": "csv"
}
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-formatter"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether CSV formatting succeeded. | true |
rowCount |
Number | Total number of data rows processed. | 2 |
columnCount |
Number | Total number of columns normalized. | 3 |
result |
String | Formatted output (CSV or ASCII table string). | "id,name,role\n1,Alice,Dev" |
data |
Array | Native array-of-arrays representation of the CSV. | [["id", "name", "role"], ["1", "Alice", "Dev"]] |
originalSize |
Number | Byte size of the original unformatted data. | 37 |
resultSize |
Number | Byte size of the formatted string output. | 27 |
formattedCsv |
String | Standard RFC 4180 formatted CSV output. | "id,name,role\n1,Alice,Dev" |
asciiTable |
String | Mono-spaced ASCII table text. | `"+----+-------+------+\n |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"rowCount": 2,
"columnCount": 3,
"inputDelimiter": ",",
"outputDelimiter": ",",
"quotePolicy": "as-needed",
"formattedCsv": "id,name,role\n1,Alice,Dev",
"asciiTable": "+----+-------+------+\n| id | name | role |\n+----+-------+------+\n| 1 | Alice | Dev |\n+----+-------+------+",
"output": "id,name,role\n1,Alice,Dev",
"result": "id,name,role\n1,Alice,Dev",
"data": [
["id", "name", "role"],
["1", "Alice", "Dev"]
],
"originalSize": 37,
"resultSize": 27
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid input: CSV payload cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to format CSV?
Integrating the CSV Formatter API into automated ETL ingestion pipelines, database export tools, or AI agent tool calling provides key benefits:
- Rapid Script Validation: Normalizes untidy user spreadsheet uploads and standardizes delimiter conventions before importing into relational databases.
- Optimized Token Efficiency for AI Agents: LLMs frequently produce ragged rows and inconsistent quoting when generating tabular data. Calling the API formats and pads columns deterministically without extra reasoning tokens.
- Deterministic Accuracy Without Hallucinations: Ensures 100% RFC 4180 compliant CSV serialization and escaped quotes.
Native Usage
How to format CSV data locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Format and normalize CSV in PowerShell
Import-Csv -Path .\input.csv | Export-Csv -Path .\output.csv -NoTypeInformationLinux / Unix (Bash)
# Format CSV as aligned table in Linux
column -t -s',' input.csvPython
Using Python csv:
import csv
with open("input.csv", mode="r", encoding="utf-8") as infile:
reader = csv.reader(infile)
rows = [[cell.strip() for cell in row] for row in reader]
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerows(rows)
print("CSV formatted successfully.")Java
Using Java Scanner and String.join:
import java.nio.file.*;
import java.util.*;
public class FormatCsvExample {
public static void main(String[] args) throws Exception {
List<String> lines = Files.readAllLines(Paths.get("input.csv"));
List<String> formatted = new ArrayList<>();
for (String line : lines) {
String[] cells = line.split(",");
for (int i = 0; i < cells.length; i++) cells[i] = cells[i].trim();
formatted.add(String.join(",", cells));
}
Files.write(Paths.get("output.csv"), formatted);
System.out.println("CSV formatted successfully.");
}
}