IT Market
Tools/Code/Documents/Text Lines to JSON Array or Object
TXT → JSON

Конвертируйте текст в JSON Array/Object

Tool guide

Text Lines to JSON

A list someone pasted into chat, one item per line, is rarely in a shape code can use. Here it becomes JSON: the Mode switch, with Array and Object (key:value), decides whether you get a list of strings or an object built from colon-separated pairs. Blank lines are skipped. Everything is computed in the browser, so internal lists are safe to work on. Useful for database seeds, localisation files and quick fixtures in tests. See also: validate the array you just built, turn the list of lines into a CSV table, parse a delimited file into JSON instead.

How to use it

  1. Paste your text into the Text Input box, one item per line, as the Line 1 / Line 2 / Line 3 placeholder shows.
  2. Pick Array under Mode when you want a plain list of strings in square brackets.
  3. Pick Object (key:value) when every line reads as key then value — the split happens at the first colon.
  4. Press Convert and the indented result appears in the JSON Output box.
  5. Press Copy and drop it into a localisation file, a database seed or a set of test data.

FAQ

What happens to a line with no colon in Object mode?

There is nothing to split, so such a line is either skipped or yields a key with an empty value. Scan your list before converting and add the missing colons. If the lines genuinely have no keys, switch to Array mode instead, which keeps every line intact as one element of the list.

What if a line contains several colons, like a time of 10:30?

The split happens at the first colon: everything before it becomes the key, the whole remainder becomes the value. A line reading start: 10:30 gives the key start and the value 10:30, which is normally what you want. A colon inside the key itself is the case that breaks, so avoid it there.

Do numbers stay numbers, or become strings?

Each line is carried across as text, so 42 comes out as "42" in quotes. That is a deliberate trade-off: automatic typing would ruin SKUs with leading zeros, phone numbers and version strings like 1.10. If you need real types, strip the quotes in your editor afterwards or cast the values in code when loading.

How are blank lines and stray whitespace treated?

Blank lines between blocks are dropped, which helps when the text was copied out of a formatted document. Leading and trailing spaces or tabs inside an item can survive into the value, though, and later cause a puzzling mismatch in a string comparison. Check the alignment in the finished JSON before shipping it.

My items are separated by commas or semicolons, not line breaks.

That is tabular data, and the CSV to JSON page handles it properly: it distinguishes a header row from a delimiter and builds an array of objects rather than a flat list. Here the separator is always a newline. The quick workaround is to replace the commas with line breaks in any editor and come back.

Does the list I paste stay on my machine?

Yes. Splitting the lines and assembling the JSON is done by a script in the open page; the box contents are not sent to a server and nothing is stored. Reloading the tab clears both boxes. That is why draft localisation strings and internal inventories are reasonable to tidy up here rather than in a third-party service.

Examples

City list for a dropdown
Before: Leeds Hull Derby
After: [ "Leeds", "Hull", "Derby" ]
Draft of a localisation file
Before: title: Basket empty: Your basket is empty submit: Place order
After: { "title": "Basket", "empty": "Your basket is empty", "submit": "Place order" }