CSV Formatter
Two different jobs behind one page, and the page is honest about which is which. Align pads every column so the file is a pleasure to read in a terminal or a code review. Tidy keeps it a strict CSV and fixes what makes one unpleasant: inconsistent quoting, stray whitespace, ragged rows, the wrong delimiter.
Try an example loads an order file with padded headers, quoted commas and inconsistent spacing.
There is no such thing as pretty CSV that is still CSV
Worth stating plainly, because it is the reason this page has two modes rather than one. CSV has no whitespace-insignificant regions. Every character between the delimiters is part of the value. So aligning columns by padding them with spaces produces something a person reads easily and a strict parser reads wrongly, unless every cell is quoted.
order_id, customer , region, units, unit_price, total
1001 , "Lovelace, Ada" , EU , 3, 40.50, 121.50
1002 , Grace Hopper , US , 1, 88.00, 88.00
1003 , "Turing, Alan" , UK , 6, 40.00, 240.00
That is beautiful in a pull request and it is not a CSV you should feed to anything. A note above the result says so every time the align mode is used, rather than letting you find out downstream.
Tidy mode makes no such trade. It produces a strict, minimal, correctly quoted CSV that any parser reads, and it is the mode to use when the file has somewhere to go.
What tidy mode fixes
- Inconsistent quoting. Files written by hand, or by three different exporters, quote some fields and not others for no reason. Tidy applies one rule throughout: quote only what needs it, or quote text fields, or quote everything, whichever you pick.
- Stray whitespace.
AdabecomesAda. Leading and trailing spaces in a CSV cell are almost always an artifact of how the file was written, and they are the reason a join that should match does not. - Ragged rows. A row with fewer fields than the widest is padded with empty cells rather than dropped, and the count of padded rows is reported. Dropping a short row silently is how a parsing problem becomes a data problem three steps later.
- The wrong delimiter. Read a semicolon file, write a comma one, or the other way round. The input delimiter is detected and the output one is yours to choose.
- A byte order mark. Stripped. Left in place it attaches itself to the first column name and survives several rounds of debugging, because the header looks perfectly normal on screen.
Quoting rules follow RFC 4180: double quotes around a field containing the delimiter, a quote, a line break or leading and trailing whitespace, and a quote inside a field written twice.
Numbers are right-aligned, and that is not decoration
In align mode, a column whose data rows are all numeric is padded from the left, so the digits line up on their units place:
item , qty
widget, 5
gadget, 120
thing , 17
That is the whole reason to align a numeric column. Left-aligned, 5 and 120 start in the same place and end in different ones, and you cannot see at a glance which is larger. Right-aligned, the magnitudes are visible without reading. A column that mixes numbers and text is left-aligned, because there is nothing to line up.
The three quoting rules
| Rule | Quotes | Use it when |
|---|---|---|
| Only when needed | fields containing the delimiter, a quote, a line break or edge whitespace | the default, and right for almost everything |
| Text fields | every non-numeric, non-empty field | the destination infers types and you want the strings pinned |
| Everything | every field, including numbers and blanks | a strict importer, or a destination that has been guessing wrong |
Quoting everything is the one that solves the leading-zero problem. A ZIP code of 01730 written bare is read as the number 1730 by Excel and by half of everything else; written as "01730" it survives in more of them, though Excel remains determined and the CSV to Excel converter is the reliable answer there.
When each mode earns its keep
- A CSV fixture in a code repository. Align it. Reviewers read it, and a padded file makes a wrong value visible in the diff.
- A file going into an importer. Tidy it, quote what needs quoting, and pick the delimiter the importer documents.
- A file somebody edited by hand. Tidy it. Hand editing produces stray spaces and inconsistent quoting more reliably than anything else.
- A table for a bug report or a wiki page. Align it, or use the Markdown converter for something that renders.
- A European export you need in a US tool. Tidy it, reading semicolons and writing commas.
Files up to 100 MB drop straight in with no row limit under that. Aligning a very wide file produces very long lines, which is worth thinking about before you do it to something with sixty columns.
Frequently Asked Questions
Will the aligned output still open in Excel?
It will open, and every value will have spaces attached to it, because Excel reads the padding as part of the field. Use tidy mode for anything a program has to read. Align mode is for human eyes, terminals and code review, and the note above the result says exactly that.
Why did a row gain empty cells?
Because it had fewer fields than the widest row in the file. It is padded rather than dropped, and the count of padded rows is reported in a note. A ragged file is usually a sign that a value contains an unquoted delimiter, and the row numbers tell you where to look.
Does it change my numbers?
No. Cells are moved as text throughout, never parsed as numbers and re-written, so 40.50 keeps its trailing zero and 01730 keeps its leading one. The only optional edit to a value is trimming leading and trailing whitespace.
How is the input delimiter chosen?
It is detected from the content, which handles comma, semicolon, tab and pipe. If detection gets it wrong, the Delimiter control at the bottom lets you name it. The output delimiter is separate, so reading semicolons and writing commas is one setting each.
What is the difference between this and the delimiter changer?
The delimiter changer does one job, and does it on files where that is all you want. This page changes the delimiter as one of several things, alongside quoting, trimming, padding and alignment.
Can I align only some columns?
No, alignment applies to the whole table, because a partially aligned table is worse than either alternative. Numeric columns are right-aligned and everything else left-aligned, which is the split that makes a table readable.
Does anything I paste leave my computer?
No. There is no upload endpoint on this page and no network request in the code that does the work. JavaScript in your own tab reads the text, processes it and hands back the result. Nothing is stored between visits either, so reloading gives you an empty box again. You can confirm it by opening your browser's network panel and watching it stay quiet while you work.
Related
Readable, or strict. Your call
Free, no account, no upload. Align it for people, tidy it for programs.
Back to the formatter