Lines to JSON array converter
For developers who need a list of cities or products as an array in code or a config file, without typing quotes and commas.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter text, format, trim spaces around each line and skip empty lines.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
Each line (after optional trimming and skipping blanks) becomes a string element, and the array is written with JSON.stringify, which escapes ", \ and control characters.
Example
Inputs: Format = Pretty (2 spaces), Trim spaces around each line = yes, Skip empty lines = yes. Result: Result: [ "Riyadh", "Jeddah", "Dubai", "Doha" ]; Elements: 4.
Riyadh Jeddah Dubai Doha
[ "Riyadh", "Jeddah", "Dubai", "Doha" ]
Limits and caveats
- Every element is a string; numbers such as 42 become "42".
Questions about this tool
Can I use the result in JavaScript?
Yes. A JSON array is a valid JavaScript array literal.
What happens to a " inside a line?
It is escaped to \" so the JSON stays valid.
Does it work with Arabic text?
Yes. Arabic letters stay as they are inside the strings, since JSON supports Unicode.
