The short answer. For a one-off list, paste into the prefix tool with prefix ", then the suffix tool with suffix ", then the joiner in CUSTOM mode with separator , — wrap the result in [ ], done with no trailing comma. In Excel, ="[" & TEXTJOIN(",", TRUE, """" & A1:A100 & """") & "]". On the command line, jq -R . file.txt | jq -s . reads one line per element and outputs a clean array. In Python, json.dumps([line.strip() for line in open("file.txt")]). The catch is escaping: values containing quotes, backslashes, or control characters need \", \\, \t — pick a method that handles that for you or you'll ship a JSON parser error to production. Decision table at the bottom.
When you need a JSON array of strings
Four cases cover most of the real need:
- API payload preparation. A REST endpoint expects
{"tags": ["a", "b", "c"]}and you have a column of tag names. - JavaScript constant injection. A frontend wants a hardcoded array of country codes, plan IDs, or feature flags.
- Test fixture generation. A test expects a list of email addresses or sample inputs.
- Configuration files. A YAML / JSON config takes a list of allowed origins, redirect URIs, or webhook URLs.
The bar is low — you just need ["item1", "item2", "item3"] with valid JSON syntax. The risk is also low — if you ship a malformed array, the parser tells you immediately. But broken arrays in production are embarrassing, and the embarrassment is usually caused by one of three things: a value containing a quote, a value containing a backslash, or a trailing comma after the last element.
How do you build a JSON array online, instantly?
Three joinlines tools chained do the whole job, no upload.
- Open the add-prefix tool. Paste your list. Set the prefix to
"(a single double-quote). Copy the result. - Open the add-suffix tool. Paste the prefixed result. Set the suffix to
"(closing double-quote, no comma). Copy. - Open the line joiner. Paste the quoted lines. In the separator input box, type
,(a single comma). Copy. Because the joiner puts separators only between items, the output has no trailing comma. - Wrap the result in
[ ]. Done —["alice","bob","carol"]— valid JSON, no clean-up needed.
The three-step chain trades a few clicks for staying entirely client-side — none of your data leaves the tab. We test the chain regularly against lists that contain edge-case characters (apostrophes, em-dashes) to make sure the prefix/suffix tool treats them literally without smart-quote substitution.
Honest limitation: this manual chain does not escape quotes or backslashes inside your values. If a value contains " or \, the resulting JSON will be invalid. For lists with known-clean values (email addresses, IDs, slugs), the chain is faster than firing up a script. For arbitrary user input, use the Python / jq path below where escaping is automatic.
How do you build a JSON array in Excel?
Modern Excel (365 / 2021) makes this a one-liner with TEXTJOIN:
="[" & TEXTJOIN(",", TRUE, """" & A1:A100 & """") & "]"
Breakdown of the magic:
""""is Excel's way of expressing a literal double quote inside a formula string. Excel escapes a quote within a string by doubling it (""= one literal quote), so the four quotes parse as: open string, doubled-quote-meaning-one-literal-quote, close string. The whole expression produces a one-character string containing a single"."""" & A1:A100 & """"wraps each cell value in quotes.TEXTJOIN(",", TRUE, ...)joins the quoted values with commas, skipping blanks."[" & ... & "]"wraps the whole thing in array brackets.
Same caveat as the browser chain: this does not escape quotes inside the values themselves. If A1 contains he said "hi", the formula produces "he said "hi"" — invalid JSON. For values with quotes, pre-process with =SUBSTITUTE(A1, """", "\""") in a helper column, then use the result in the main formula.
Google Sheets uses identical syntax. Both spreadsheets cap output at 32,767 characters per cell — for arrays longer than that, switch to jq or Python.
How do you build a JSON array with jq?
jq is the right tool when escaping needs to be correct without effort, and when the input is a file rather than a paste.
jq -R . file.txt | jq -s .
Two passes:
jq -R .reads raw lines from the file and outputs each as a properly-escaped JSON string — quotes, backslashes, control characters all handled automatically.jq -s ."slurps" the stream of strings into a single array.
The output is pretty-printed with newlines and indentation. For compact one-line output:
jq -R . file.txt | jq -sc .
The -c flag is "compact". To skip blank lines first:
grep -v '^[[:space:]]*$' file.txt | jq -R . | jq -sc .
This is the canonical "one file in, one valid JSON array out" recipe on Unix. Installing jq is one brew install jq or apt install jq away on the standard package managers.
How do you build a JSON array in Python?
The standard library handles everything:
import json
with open("file.txt") as f:
items = [line.rstrip("\n") for line in f if line.strip()]
print(json.dumps(items, indent=2))
json.dumps handles every escape correctly — quotes, backslashes, Unicode. indent=2 pretty-prints; remove it for compact output. The if line.strip() filter drops blank lines.
For a Python one-liner from the shell:
python -c "import json,sys; print(json.dumps([l.rstrip() for l in sys.stdin if l.strip()]))" < file.txt
If you have jq already, the jq recipe is shorter. If you have Python but not jq, this is the safer fallback.
What about arrays of objects, not just strings?
The above recipes all produce arrays of strings: ["alice", "bob"]. For arrays of objects with multiple fields per row ([{"name": "alice", "email": "[email protected]"}, ...]), the tool of choice is jq reading a CSV:
jq -Rsn '
[inputs | split(",")] as $rows
| $rows[1:] | map({name: .[0], email: .[1]})
' data.csv
The $rows[1:] skips the header. The map turns each row array into an object with named fields. Caveat: this naive split(",") breaks on any field that contains an embedded comma (e.g. "foo, bar"). For real CSV-escape handling, switch to Python with csv.DictReader:
import csv, json
with open("data.csv") as f:
reader = csv.DictReader(f)
print(json.dumps(list(reader), indent=2))
Three lines, full CSV escape handling, every field becomes a key. The browser-tool chain doesn't fit this case — once you have multiple fields per row, you've left "list" territory and entered "structured data" territory.
Which method should you use?
| Your situation | Best method |
|---|---|
| One-off list, clean values (no quotes / backslashes) | Prefix + suffix + joiner chain |
| Excel column, clean values, < 30,000 chars output | =TEXTJOIN(",", TRUE, """" & A:A & """") |
| Arbitrary user input (may contain quotes) | jq -R . file.txt | jq -sc . or Python json.dumps |
| File on disk, scripted | jq — one-line, perfect escaping |
| Need an array of objects (multi-field per row) | Python csv.DictReader + json.dumps |
| Output larger than 32k characters | jq or Python — spreadsheets cap per-cell at 32,767 |
| Sensitive data | Browser-tool chain or local script — never an upload converter |
Frequently asked questions
Why does my JSON array fail to parse?
Three common reasons. (1) Unescaped double-quote inside a value: "he said "hi"" needs to be "he said \"hi\"". (2) Trailing comma after the last element: ["a", "b", "c",] is invalid JSON (some parsers accept it, the spec doesn't). (3) Unescaped backslash: a Windows path like "C:\Users" needs "C:\\Users". Tools that handle escaping automatically (jq, Python's json) avoid all three. The browser-tool chain and Excel TEXTJOIN do not.
How do I remove the trailing comma from the last element?
The recipe above already avoids it — the joiner puts separators only between items, not after the last one. Avoid the alternative "suffix with comma + manual newline" approach precisely because it leaves a trailing comma on the last line. Excel's TEXTJOIN handles this correctly by design, and jq never produces trailing commas because it builds the array as a real data structure rather than by string concatenation.
How do I build a JSON array with non-string values (numbers, booleans)?
Don't quote the values. For an array of numbers from an Excel column: ="[" & TEXTJOIN(",", TRUE, A1:A100) & "]" — same recipe minus the """" & wrapping. For mixed types, you're outside string-manipulation territory; jq or a script is the right path. The joiner handles the numeric case too — just paste numbers, separator ,, wrap in [ ].
What's the size limit for a JSON array in practice?
Depends on what consumes it. JavaScript engines handle arrays of millions of items in memory but parsing the JSON text is the slow step. APIs typically cap payloads at 1–10 MB. For files, jq streams — no practical limit. For Excel, the 32,767-character per-cell limit hits well before the JSON spec or parser limits.
Can I build a JSON object (not array) from the same list?
Yes, if the list is keys + values alternating or if you want every line to become a key with the same default value. For {"a": true, "b": true, "c": true}: use the prefix tool with ", suffix with ": true,, joiner with newline, wrap in { }. For key:value pairs from two parallel lists, you need a script — Python with dict(zip(keys, values)) is the cleanest path.
Is it safe to paste a sensitive list into an online JSON converter?
Most "CSV/list to JSON" converter websites upload your data to their server — even the ones that claim "client-side", because verifying is harder than building. The joinlines chain runs entirely in your browser: open DevTools → Network, paste, run each step, watch for outbound requests. Zero requests means the data stayed in your tab. We make this verifiable by design, because the conversion problem is too common for "trust me" to be the answer.
— the joinlines team, 2026-05-11