Articles
Published · November 18, 2026

JSON Lines: One JSON Record per Line in a Plain-Text File

JSON Lines is a plain-text format with one valid JSON value per line. Here are its three rules, how it compares to NDJSON, and when to skip it.

Also in: Español中文हिन्दी

JSON Lines is a plain-text format where every line is one valid JSON value, usually an object, and the file is usually saved as .jsonl. A JSON Lines file is not one JSON document: you read it a line at a time, so you can append, split, and search it with ordinary text tools.

Quick answer

Here is a complete JSON Lines file with three records:

{"id": 1, "event": "open", "file": "notes.md"}
{"id": 2, "event": "save", "file": "notes.md"}
{"id": 3, "event": "close", "file": "notes.md"}

Each line parses on its own. No outer [ ], no commas between records, no state to track. According to jsonlines.org, the format is "a convenient format for storing structured data that may be processed one record at a time", and it works well with Unix-style text tools and shell pipelines.

How it actually works

The three rules

The JSON Lines page lists three requirements:

  1. UTF-8 encoding. A byte order mark (U+FEFF) must not be included. If you want a file that stays plain ASCII, you can escape non-ASCII characters with JSON's \u sequences.
  2. Each line is a valid JSON value. Objects and arrays are the most common, but any JSON value is allowed. null is a valid line. A blank line is not.
  3. The line terminator is `\n`. A \r\n ending also works, because whitespace around a JSON value is ignored when parsing. If you have ever fought with mixed endings, our piece on CRLF vs LF line endings explains where they come from.

A newline after the last value is strongly recommended but not required. If one is there, it must be the last byte in the file. Ending every record with a newline is what makes it safe to join two files with cat.

Why one line per record works

Wikipedia's JSON streaming article points out that JSON is non-concatenative: gluing two JSON documents together does not give you a valid JSON document. A line break fixes that, and the reason it is safe is that JSON does not allow raw newline characters inside strings. They must be written as \n. So a real line break in the file can only mean "next record".

That also rules out pretty-printing: a record can't spread across several lines. Each one stays on a single line.

Working with it from the command line

Because records are lines, the tools you already have apply:

wc -l events.jsonl            # how many records
head -n 2 events.jsonl        # peek at the first two
grep '"event": "save"' events.jsonl
echo '{"id": 4, "event": "open"}' >> events.jsonl   # append

Appending is the big win. Adding a record to a JSON array means rewriting the closing bracket and fixing commas. Adding a record to a JSONL file means writing one more line. Searching works the same way as with any other text file; see searching with grep and ripgrep for patterns that carry over.

To convert pretty-printed or concatenated JSON into lines, jq can do it with its compact output flag, as the Wikipedia article notes:

jq --compact-output . < concatenated.json > lines.json

When to use it (and when to skip it)

Good fits

  • Logs and event streams. The format is described as a great fit for log files, since each event is one self-contained line.
  • Exports and datasets. You can read, filter, or split a large file without loading it all into memory.
  • Messages between programs. One process writes lines, another reads them.
  • Clean diffs. One record per line means a changed record is one changed line in version control.

JSONL, NDJSON, and RFC 7464

Wikipedia describes NDJSON and JSON Lines as two names for equivalent line-delimited formats. One difference it mentions is history: the older NDJSON spec allowed comments on lines starting with //, and the current one does not.

RFC 7464 is a different, standardized format called JSON text sequences. Each JSON text is prefixed by an ASCII Record Separator (0x1E) and ends with a line feed, and its media type is application/json-seq. It isn't JSON Lines, so don't mix the two up in a pipeline. For JSON Lines, application/jsonl is suggested as a MIME type, but the site says that is not yet standardized.

Skip it when

  • You need one document. An API response or a manifest with nested metadata is simpler as a regular JSON object or array.
  • You hand-edit settings. Config files want comments and readable nesting; see JSON, YAML, or TOML for how to choose.
  • Your data is flat and tabular. A CSV is more compact, as long as you know the CSV quoting rules.
  • You want comments or pretty-printing. JSON Lines allows neither.

How Carets fits in

A .jsonl file is just text, which makes it a good match for a quick editor: open it, scan a few records, fix a line, save. Carets is a native notes and code editor for iPhone, iPad, and Mac that handles plain text and code in one place, with syntax highlighting for code and config files. You can keep log samples and exports alongside your notes, organized into files, projects, and tags, and the files stay plain text, so any other tool can read them.

One limit to be upfront about: Carets is an editor, not a JSON Lines validator. For a strict check of a large file, run jq or a script too.

Get Carets for iPhone, iPad, and Mac on the App Store.

Frequently Asked Questions

Is JSONL the same as NDJSON?

Wikipedia describes them as equivalent line-delimited formats. The older NDJSON spec allowed // comments; the current one does not, which matches JSON Lines.

Can a JSON Lines file have blank lines?

The specification says a blank line is not a valid value, so a strict file has none. Some readers skip them, but you should not rely on that.

What file extension should I use?

Use .jsonl. If you compress it with gzip or bzip2, the names become .jsonl.gz or .jsonl.bz2.

Can I pretty-print records in JSON Lines?

No. Every record must fit on one line. Pretty-printed JSON needs a parser that handles concatenated JSON, and a line-based JSON Lines parser cannot read it.