Text & writing
How to Add Commas to the End of Each Line
Turning a column of values into a comma-separated list is one of the most common text chores — for a SQL query, an array in code, a CSV row, or a list in a message. Adding a comma to the end of each line is the quick part; the details that trip people up are the last comma, quoting, and blank lines.
Ready to try the tool this guide describes?
Where comma-terminated lines are used
- SQL: the values inside WHERE id IN ( … ).
- Code: the items of an array or list.
- Data files: fields or rows that need a separator before they are joined.
- Email and chat: a list that will be flattened onto one line.
The last comma
When a trailing comma is not allowed, delete the comma after the final line before using the result.
| Format | Trailing comma after the last item |
|---|---|
| JSON | Not allowed — the file will not parse |
| SQL IN ( … ) lists | Not allowed — a syntax error |
| JavaScript and TypeScript arrays | Allowed |
| Python lists | Allowed |
Text values need quotes
Numbers can usually be listed as they are, but text values need quotes in code and SQL: 'apple', rather than apple,. Add the opening quote at the start of each line and the closing quote plus comma at the end — two passes, one for each side.
Joining onto one line instead
If you want “apple, banana, cherry” on a single line, a spreadsheet formula such as =TEXTJOIN(", ", TRUE, A2:A20) joins a column with a separator and skips blanks. For a list pasted as lines, adding commas and then removing the line breaks gives the same result.
Add Commas to Each Line FAQ
- How do I add a comma to the end of every line?
- Paste the lines into an add-suffix tool and enter a comma as the suffix. Every non-blank line gets one.
- Why does my JSON fail after adding commas?
- JSON does not allow a comma after the last item in an array. Remove the final comma.
- Do I need quotes around each value?
- For text values in code and SQL, yes. Numbers normally do not need them.
- How do I put the list on one line?
- Use TEXTJOIN in a spreadsheet, or add the commas and then remove the line breaks.
- Should blank lines get a comma?
- No — a comma on its own line creates an empty value. Remove blank lines or leave them without a suffix.
Related guides
- Wrap Lines in QuotesWhich quote marks SQL, JSON, JavaScript, Python, and CSV expect, how to add them to every line, and how to escape values that already contain quotes.
- Suffix After Invisible SpacesWhy text added to the end of a line can appear after a gap or even at its start, where hidden spaces and carriage returns come from, and how to trim them.
Open the tool
Jump into Add Suffix to Each Line when you are ready to process your files.
