What is a list converter?
A list converter reshapes text that has one item per line into another layout: a comma-separated line, a quoted list ready for code, an SQL IN (...) clause, an HTML list, a JSON array or the same list cleaned and sorted. It is the quick fix for the job every analyst and developer repeats: a column copied from a spreadsheet, a list of IDs from an email or lines from a log has to become something a query, a script or a form can accept.
By hand, with find and replace, the usual mistakes are the ones that break things: a trailing comma, a duplicate ID, a space before a value, an empty line in the middle. This tool applies a chain of small steps in a fixed order and shows the result as you type, so you can switch options until the output is exactly what you need.
The steps are: read the items (one per line, or from a JSON array), optionally split each line further, trim spaces, remove a prefix or suffix from each item, convert to lowercase, drop empty items, remove duplicates, reverse or sort, wrap each item, and finally join them with a separator and wrap the whole list. Everything runs in your browser; the list never leaves your computer.
How to convert a list
- Paste your list in Your list, one item per line. The tool opens with a short fruit list so you can see the result immediately.
- Choose the Separator that goes between items (the default is a comma and a space). Turn on Keep line breaks if each item should stay on its own line.
- Wrap items with Before each item and After each item, for example a quote on both sides. Wrap the whole list with Before the list and After the list, for example
(and). - Clean the items: Trim list items and Remove duplicates are on by default; Convert to lowercase, Remove from item (a prefix and a suffix to strip) and Split lines by (a character such as a comma) are there when you need them.
- Pick a Sort list order (ascending or descending), turn on Sort numbers naturally so that
2comes before10, or Reverse list. Reversing and sorting exclude each other, so the sort option is disabled while the list is reversed. - For JSON, turn on Read input as JSON (an array's values, or an object's keys, become the items) and Output as JSON array.
- Copy the output. Your switches and the sort order are remembered; the text fields and the list itself are not, because they may hold private data.
Examples of list conversion
A column to one comma-separated line
Input:
banana
apple
cherry
apple
date Output with the defaults: banana, apple, cherry, date. The duplicate apple is removed and the spaces around date are trimmed.
An SQL IN clause
With the list 1, 2, 3, the separator ,, Before the list IN ( and After the list ), the output is IN (1,2,3). For text values add a quote as Before each item and After each item.
Quoted items inside parentheses
The list ana, bruno, ana, carla with a single quote before and after each item, ( and ) around the list and the default separator gives ('ana', 'bruno', 'carla').
Natural number sorting
The list 10, 9, 100, 2 sorted ascending gives 10, 100, 2, 9 as text. With Sort numbers naturally it gives 2, 9, 10, 100.
An HTML list
Items 1, 2, 3 with <li> and </li> around each, an empty separator, Keep line breaks on and <ul> and </ul> around the list produce:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>From a JSON array to a clean JSON array
Reading ["a","b","a",3] as JSON and writing JSON gives ["a","b","3"]: duplicates are removed and every value becomes text.
Common errors and how to fix them
- The input is not valid JSON (Unexpected end of JSON input). Paste a JSON array or object, or turn off "Read input as JSON". The text has a missing bracket, quote or comma. Check where the message points, or turn the switch off if the input is a plain list.
- JSON input must be an array (its values become the items) or an object (its keys become the items). You pasted a bare string or number. Wrap it in brackets:
["value"]. - My numbers are sorted as text.
10comes before9alphabetically. Turn on Sort numbers naturally. - The empty lines disappeared. Empty items are always removed, so a blank line never leaves a double comma.
- The separator field is greyed out. With Output as JSON array on, the separator is not used. Turn it off to use a custom one.
- Lines end with a backslash. If the list comes from a shell script, turn on Ignore trailing backslash.
Frequently asked questions
How do I convert a column to a comma-separated list?
Paste the column, keep the separator as a comma and a space, and copy. Duplicates and blank lines are cleaned at the same time. To do the reverse, put a comma in Split lines by, leave the separator empty and turn on Keep line breaks.
How do I remove duplicates from a list?
Remove duplicates is on by default and keeps the first occurrence of each item. To compare two lists line by line instead, use the text diff.
How do I put quotes around every item?
Type the quote in Before each item and After each item. For other line edits such as numbering, removing or sorting lines, the line tools may be a better fit.
Can I change the case of the items?
Use Convert to lowercase here, or the case converter for camelCase, snake_case and the other styles, which also works line by line.
How do I turn a list into JSON or CSV?
Output as JSON array gives a JSON array of strings; JSON to CSV and the data converter take it from there.
How to convert a list in code
JavaScript
const text = 'banana\napple\ncherry\napple\n date ';
const items = [...new Set(text.split(/\r?\n/).map(s => s.trim()).filter(Boolean))];
items.join(', '); // 'banana, apple, cherry, date'
items.sort().join(', '); // 'apple, banana, cherry, date'
['10', '9', '100', '2'].sort((a, b) => a.localeCompare(b, undefined, { numeric: true })); // 2, 9, 10, 100Python
text = 'banana\napple\ncherry\napple\n date '
items = list(dict.fromkeys(s.strip() for s in text.splitlines() if s.strip()))
', '.join(items) # 'banana, apple, cherry, date'
', '.join(sorted(items)) # 'apple, banana, cherry, date'Bash
printf 'banana\napple\ncherry\napple\n' | sort -u | paste -sd, - # apple,banana,cherry