Illustration of a vertical list of words each followed by a comma, feeding into a bracketed list

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.

The last comma comparison
FormatTrailing comma after the last item
JSONNot allowed — the file will not parse
SQL IN ( … ) listsNot allowed — a syntax error
JavaScript and TypeScript arraysAllowed
Python listsAllowed

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

Open the tool

Jump into Add Suffix to Each Line when you are ready to process your files.

← Back to all guides

More from Looty

Explore Looty’s Ecosystem

Discover more ways Looty can help you learn, organize, create, and make an impact.