StringMash.com

JSONL to JSON converter

JSON Lines to a JSON array and back, with the failing line named.

Conversion
82 characters
Updates as you type

Swap for JSON to JSONL

Using the converter

Paste JSON Lines, one JSON value per line, and they come out as a single JSON array, formatted for reading. Blank lines are skipped. If a line isn't valid JSON, the error says which line, so a broken record in a long log is quick to find.

Swap to go the other way: paste a JSON array and each item comes out on a line of its own, compact, ready to append to a .jsonl file.

What JSON Lines is

A JSON Lines file holds one complete JSON value on each line, usually an object. It's also called NDJSON, newline-delimited JSON. Because every line stands alone, a program can read the file a line at a time without loading the whole thing, and can add a record just by appending a line.

That makes it common for logs, data exports and machine learning datasets, where files grow long and get written a record at a time. A normal JSON array can't do that: it isn't valid until its closing bracket, so the whole file has to be read before any of it can be used.

A worked example

LineJSON LinesItem in the JSON array
1{"id":1,"tags":["new"]}[{"id":1,"tags":["new"]},
2{"id":2,"note":"line one\nline two"}{"id":2,"note":"line one\nline two"},
3nullnull]

Reading the example

The array is shown compact in the table; the converter formats it for reading. Each line is a whole JSON value on its own, so there are no commas between records and no brackets around them. The line break inside the second note is written as \n, because a real line break would end the record. Line 3 is just null: any JSON value is allowed on a line, not only objects, though objects are by far the most common.

Put a stray comma after the last field of a record, as in {"id": 3, "name": "Katherine",}, and the converter stops and names line 3. In a log with thousands of lines, that's the line to fix.

JSON Lines and NDJSON side by side

JSON Lines (jsonlines.org)NDJSON (ndjson-spec)
Each lineOne valid JSON valueOne JSON text, per RFC 8259
Line ending\n, and \r\n works too\n, which may follow a \r
Blank linesNot validA parser may skip them, if it says so
File extension.jsonl (.jsonl.gz when compressed).ndjson
Media typeapplication/jsonl, not yet standardizedapplication/x-ndjson
Text encodingUTF-8UTF-8, through RFC 8259, which requires it between systems

Questions

What's the difference between JSONL and NDJSON?

In practice, nothing: both mean one JSON value per line, separated by newlines. The converter reads either.

Can a JSON Lines record span several lines?

No. Each record has to fit on one line, so any line breaks inside a string are written as \n.

Why won't my JSON convert to JSONL?

JSON Lines is a list, so the JSON has to be an array, starting with [. To turn a single object into one line, wrap it in [ and ] first.

Why does the converter skip blank lines when JSON Lines says they aren't valid?

A blank line usually means a trailing newline at the end of the file or a gap left by hand editing, not a lost record, so stopping on it would only get in the way. The NDJSON spec allows a parser to skip them as long as it says so, and this one does. The JSON to JSONL direction never writes a blank line.

Sources

Added . Last updated and reviewed . What's new