TXT to JSON Converter Online

Convert plain text, TXT files, logs, key/value records, paragraphs, and delimited rows into clean JSON. Preview instantly, choose structure and formatting, then download a valid .json file. No upload or signup required.

TXT to JSON Example

Plain Text Input
text
name: Alice Johnson
role: Data Engineer
active: true
JSON Output
json
{
  "name": "Alice Johnson",
  "role": "Data Engineer",
  "active": true
}

The Same Text in Each Mode

The mode decides how the text is cut up, so the same input gives very different JSON. Here is one key/value file converted with default options (trim whitespace, skip empty lines, parse values on). Objects are shown on one line to save space; the tool pretty-prints them.

textproducts.txt
sku: A-100
price: 19.99
in_stock: true

sku: B-200
price: 5
in_stock: false

Lines

JSON
[
  "sku: A-100",
  "price: 19.99",
  "in_stock: true",
  "sku: B-200",
  "price: 5",
  "in_stock: false"
]

One string per non-empty line. The text is not split into keys, so this fits lists, not records.

Paragraphs

JSON
[
  "sku: A-100\nprice: 19.99\nin_stock: true",
  "sku: B-200\nprice: 5\nin_stock: false"
]

One string per blank-line-separated block. Line breaks inside a block are kept as \n.

Key/value

JSON
[
  { "sku": "A-100", "price": 19.99, "in_stock": true },
  { "sku": "B-200", "price": 5, "in_stock": false }
]

One object per block, with numbers and booleans parsed. The right mode for this input.

Delimited rows

JSON
[
  { "sku_A-100": "price: 19.99" },
  { "sku_A-100": "in_stock: true" },
  ...
]

No comma, tab, pipe, or semicolon splits these lines, so each line is one cell and the first line became a header. A single odd key like this means you picked the wrong mode.

Delimited Rows: What to Expect

Pipe-delimited text
text
id|name|joined|score
007|Ana Lima|2024-03-01|91.5
12|"Ben | Co"|2024-04-15|
JSON Output
json
[
  {
    "id": "007",
    "name": "Ana Lima",
    "joined": "2024-03-01",
    "score": 91.5
  },
  {
    "id": 12,
    "name": "Ben | Co",
    "joined": "2024-04-15",
    "score": ""
  }
]

Auto detect looks at the first 15 non-empty lines and picks whichever of comma, tab, pipe, or semicolon splits them into the most consistent columns. It never picks Spaces; choose that manually for whitespace-aligned text, where any run of spaces counts as one separator and quotes are not recognized.

Quotes: a delimiter inside double quotes stays in the value ("Ben | Co"), and a doubled quote ("") becomes one literal quote. Each line is one row, so a quoted value cannot span several lines.

Ragged rows: missing cells become empty strings, not null; only the literal text null becomes null. With First row headers on, cells beyond the header's column count are dropped. With it off, keys are field_1, field_2, and so on, up to the widest row.

Mixed types: Parse values works cell by cell, so 007 stays a string while 12 becomes a number in the same column. If a column must have one type, such as IDs or ZIP codes, turn Parse values off and convert types in your own code. For spreadsheet-style output instead of JSON, the TXT to CSV converter writes the same rows to a .csv or .tsv file, where every cell is plain text; to check the JSON result as a grid, paste it into JSON to Table.

Key/Value Parsing Details

Each line is split at the first :, =, or tab, whichever comes first. That keeps values like url: https://example.com and time=10:30 intact, but a line with no label that happens to contain a colon is split too: 10:30 standup becomes "10": "30 standup". Lines with no separator at all are kept as value_1, value_2, and so on, numbered by their position in the record.

Keys are case-sensitive after cleaning, so First Name and first name become two separate fields (First_Name and first_name). Records are separated by blank lines only; a line with just spaces also counts as blank. With Parse values on, a value written as JSON, such as tags: ["a", "b"] or meta: {"v": 2}, becomes a real array or nested object; if you need flat columns afterwards, run the result through the JSON Flattener.

Lines mode parses values too, which means text where every line is already a JSON object turns into an array of objects. For real JSONL files, though, the JSONL to JSON converter is the better fit: in Lines mode a malformed line silently becomes a string instead of being reported. To try the modes on realistic input, grab a file from the sample TXT files page.

How It Works

1

Paste or upload

Paste text or upload a .txt file.

2

Choose structure

Lines, paragraphs, key/value records or delimited rows. Adjust output in Options.

3

Copy or download

Copy the JSON or download it as a .json file.

TXT to JSON in Python

If you need repeatable conversion, Python can parse predictable key/value blocks and serialize them with the built-in json module. The online tool is faster for interactive cleanup; scripts are better for recurring jobs.

Pythontxt_to_json.py
import json

blocks = """name: Alice Johnson
role: Data Engineer
active: true

name: Mateo Rivera
role: Analytics Lead
active: true""".split("\n\n")

records = []
for block in blocks:
    item = {}
    for line in block.splitlines():
        key, value = line.split(":", 1)
        item[key.strip()] = value.strip()
    records.append(item)

with open("text-output.json", "w", encoding="utf-8") as file:
    json.dump(records, file, indent=2)

Frequently Asked Questions

Complete TXT to JSON Guide

How to Convert TXT to JSON Online

TXT files are flexible, but they rarely carry enough structure for APIs, apps, or automation. JSON gives that same text predictable fields, arrays, and objects so it can move into code, databases, QA fixtures, workflow tools, and data pipelines.

Choose the Right TXT to JSON Mode

Use Lines when each line should become one JSON array item. This works well for lists of IDs, keywords, URLs, names, or notes. Use Paragraphs when blank lines separate larger text blocks such as descriptions, article snippets, support replies, or copied document sections.

Use Key/value when text looks like name: Alice, active=true, or tab-separated fields. Blank lines create separate JSON records. If a key repeats inside one record, the last value wins, and a single record without the root wrapper is output as one object instead of an array. Use Delimited rows for CSV-like, TSV-like, pipe-delimited, or semicolon text that should become an array of JSON objects.

Why Smart Value Parsing Helps

When smart parsing is enabled, values such as true, false, null, and numbers become real JSON booleans, nulls, and numbers instead of plain strings. This makes the output easier to use in JavaScript, APIs, import jobs, tests, and schema validation. Turn it off for long numeric IDs: integers above 2^53 cannot be stored exactly as JSON numbers in the browser and would be rounded.

TXT to JSON Best Practices

  • Use key/value mode when every line has a label and value.
  • Use delimited rows when your text already has columns.
  • Turn on the root wrapper when an API expects a named property such as items.
  • Keep pretty print enabled while reviewing and disable it for compact files.
  • Preview the JSON before importing text copied from PDFs, terminals, or spreadsheets.

When to Use JSON Instead of Plain Text

Use JSON when the next step is an app, API, script, test fixture, data import, or structured handoff. If you need spreadsheet output instead, use the TXT to CSV converter. If your destination needs XML, use the TXT to XML converter.

Related Guides