Developer Lists

Text to JSON array

What to do

Transformed in your browser · nothing is uploaded

Local · escaped with JSON.stringify, not by hand
Advertisement
320 × 100

Turns a list of lines into a JSON array of strings, escaped properly rather than by hand; quotes, backslashes, tabs and control characters all come out valid. Blank lines are dropped, every value is trimmed, and the array is printed one value per line, indented two spaces.

How to use the text to json array

1 Paste one value per line.
2 Read the array. It is ready to paste into a .json file.
3 Check any line that contained a quote or a backslash.
4 Copy it, or save it as a file.

Escaping is the whole reason to use a tool instead of adding quotes by hand. A line reading say "hello" comes out as "say \"hello\"", and back\slash as "back\\slash". Wrap those in quotes yourself and you get "say "hello"", which is not valid JSON, and the failure surfaces wherever the file is eventually parsed, a long way from where it was built. A tab inside a value becomes \t for the same reason. A paste from Windows brings a carriage return on every line; those are removed along with the line breaks rather than escaped into the values.

Two limits worth knowing. Everything comes out as a string, because a flat list carries no type information: 42 becomes "42" and true becomes "true". If you need real numbers, booleans or objects, start from a header row in the CSV to JSON converter instead. And accented characters and emoji are written as themselves rather than as \u escapes; café stays café. That is valid JSON, which is Unicode text, and every conformant parser reads it; only a system that insists on plain ASCII will complain.

Questions

A value containing a double quote or a backslash makes the JSON invalid, and it fails at whatever parses it later rather than here.

MDN, working with strings
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding