Skip to main content

NDJSON Definition

Official specification and technical standards for NDJSON format

A precise engineering blueprint of a single NDJSON line under a glass dome

Formal Definition

Newline Delimited JSON (NDJSON), also known as JSON Lines (JSONL), is a text format for storing structured data. Each line consists of a valid JSON value, separated by the newline character \n (Line Feed, U+000A).

The format is designed for convenient storage and processing of structured data that may be processed one record at a time, making it ideal for streaming, logging, and append-only data scenarios.

That is the whole format: no header, no footer, no envelope, no length prefix. Because the rules are so short, most of what people believe about NDJSON is convention, not specification. This page separates the two.

New to the format? The five-minute quick start walks through writing your first file. Already have one? Run it through the NDJSON validator and look up whatever it reports in the parser error dictionary.

Specification iconNDJSON at a Glance

Full nameJSON Lines. Also called NDJSON (Newline Delimited JSON) and, in older projects, LDJSON (Line Delimited JSON).
What it stands forJSON plus L for Lines: a file of JSON values, one per line.
File extension.jsonl or .ndjson. Compressed files are usually .jsonl.gz.
Media typeapplication/x-ndjson or application/jsonl. Neither is registered with IANA. See MIME type below.
EncodingUTF-8, with no byte order mark.
Record separatorLine Feed, \n (byte 0x0A). \r\n also parses.
What a line holdsAny single JSON value. In practice, almost always an object.
Header or footerNone. The first byte of the file is the first byte of the first record.
CommentsNot allowed, because JSON has none.
Built-in schemaNone. Each line is self-describing; lines may differ in shape. Pair it with JSON Schema when you need a contract.
Specificationjsonlines.org (2013) and the NDJSON specification (1.0.0, 2014). Community documents, not a formal standard.
Built onJSON (RFC 8259) and UTF-8 (RFC 3629).

NDJSON vs Standard JSON

NOT a Single Valid JSON Document

An NDJSON file as a whole is not a valid JSON document. You cannot wrap the entire file in [ and ] and parse it as a JSON array.

// This is NOT valid JSON:
{"id": 1}
{"id": 2}
{"id": 3}

No Commas Between Lines

Unlike items in a JSON array, there are no commas separating the JSON objects on each line.

// NDJSON - NO COMMAS:
{"name": "Alice"}
{"name": "Bob"}

// JSON Array - COMMAS REQUIRED:
[
  {"name": "Alice"},
  {"name": "Bob"}
]

No Outer Array

The entire collection of objects is not wrapped in an outer array ([ and ]). Each line stands alone.

Preserves JSON Structure

Unlike CSV, each line is a full JSON object, so it perfectly supports nested objects, arrays, and all JSON data types.

{"user": "alice", "tags": ["admin", "dev"], "meta": {"role": "lead"}}
{"user": "bob", "tags": ["user"], "meta": {"role": "member"}}

The Three Rules of the Specification

The specification at jsonlines.org states the format in exactly three rules, quoted verbatim below. Anything else is convention or advice, not conformance.

The three rules of NDJSON: 1 UTF-8 encoding with no byte order mark, 2 one JSON value per line, usually an object, 3 a newline ends each line and a trailing newline is fine
The whole specification fits on three cards.

Rule 1: UTF-8 Encoding

The file must be UTF-8, with no alternative: UTF-16, Latin-1, and Shift-JIS files are not NDJSON, however cleanly they parse in the tool that wrote them. UTF-8 byte sequences are self-describing, so no encoding declaration is needed. Rule 1 carries one more clause most summaries drop: "Like the JSON standard a byte order mark (U+FEFF) must NOT be included". The BOM ban is part of the rule, not an inherited nicety.

{"name": "Müller"}
{"city": "北京"}
{"emoji": "🔥"}

Rule 2: Each Line is a Valid JSON Value

The wording rewards close reading: "any JSON value is permitted. e.g. null is a valid value but a blank line is not". Two things follow. A line is not required to be an object, and an empty line is not an empty record - it holds no JSON value, which is a parse error.

{"name": "Alice"}
["apple", "banana"]
"Hello World"
42
null

Rule 3: Line Terminator is "\n"

The terminator is Line Feed, U+000A. The specification then adds the sentence most summaries leave out: "This means '\r\n' is also supported because surrounding white space is implicitly ignored when parsing JSON values". CRLF is not a second terminator added for Windows - it works because whitespace around a value is ignored. The rule also settles the final newline: one after the last value is "strongly recommended but not required", and if it is there it must be the last byte in the file.

{"id": 1}\n
{"id": 2}\r\n
   {"id": 3}   \n

Two Rules That Are Not Actually Rules

Both claims below are repeated constantly and both are good advice. Neither is a conformance requirement, and treating them as one makes teams reject valid files.

Myth: CRLF line endings are invalid

Reality: CRLF is explicitly permitted. Rule 3 says so in as many words. A file written on Windows with \r\n terminators is valid NDJSON and needs no conversion to be correct.

Preferring LF is still sound engineering: it keeps files byte-identical across platforms and sidesteps naive splitters that leave a trailing \r glued to the value. But that is a practice, not a rule.

Myth: Every line must be a JSON object

Reality: any JSON value is permitted. A line holding null, 42, "text", or [1, 2] conforms. The specification does not require records to be objects.

The convention runs the other way, and runs strongly. Object-per-line is what nearly every real file does and what libraries, log shippers, and bulk-import endpoints expect; many reject a scalar line the specification permits. So the position splits: a bare scalar line is conforming NDJSON, and still a poor choice for a file you hand to other software.

// Conforming, but uncommon:
null
"a bare string record"
[1, 2, 3]

// Conventional, and what tooling expects:
{"id": 1, "value": 42}

Two Specifications, One Format

Two documents describe this format. They cover the same bytes and differ in name, extension, suggested media type, and one point of parser behavior: NDJSON explicitly lets a reader skip blank lines, jsonlines.org does not.

JSON Lines (jsonlines.org, 2013)

Publishes the three rules above, names the format "Newline Delimited JSON", uses the .jsonl extension, and suggests application/jsonl while stating plainly that it is "not yet standardized". This is what most people mean by "the NDJSON spec", and the naming this site follows.

NDJSON (GitHub specification, 1.0.0 - 2014)

A separate community specification on GitHub, naming the format "Newline Delimited JSON", using the .ndjson extension and application/x-ndjson. Its own header records a 2013 creation date and version 1.0.0 dated 19 October 2014, and it has not been revised since. It describes the same structure, UTF-8 requirement, and whitespace tolerance.

How the Two Relate

They are the same format. A file satisfying one satisfies the other, and nothing changes when you rename data.jsonl to data.ndjson. Only the vocabulary and recommended media type differ, which is why the MIME question below has no clean answer.

Neither went through the IETF, W3C, ECMA, or ISO. There is no working group and no version to cite; the format is stable because it is trivial, not because anyone ratified it. The history of the format covers how both names emerged, and the NDJSON glossary defines the vocabulary used throughout this page.

JSONL, NDJSON, LDJSON and JSON-seq Compared

Five names turn up when people search for this format. Three are the same thing. Two are not, and an NDJSON reader will choke on them.

Map of names: JSON Lines (.jsonl), NDJSON (.ndjson) and LDJSON (older name) are the same format, while JSON Text Sequences (RFC 7464) is a different format
Same bytes under three names. JSON Text Sequences is the odd one out.
NameExtensionSeparator between valuesSame as NDJSON?Where you meet it
Newline Delimited JSON (NDJSON).jsonlNewlineYesAI training files, data exports, datasets
NDJSON.ndjsonNewlineYesStreaming HTTP APIs, Elasticsearch bulk requests
LDJSON.ldjsonNewlineYes, an older nameOlder Node.js stream libraries
JSON Text Sequencesno standard oneRecord Separator byte (0x1E) before each value, newline afterNoRFC 7464, media type application/json-seq
Concatenated JSONnoneNothing required; values simply follow each otherNo, though every NDJSON file is also valid concatenated JSONSome streaming parsers and command-line tools

The practical test: if you can split the file on the newline byte and hand every piece to a JSON parser, it is NDJSON. A JSON Text Sequence fails that test because each piece starts with an extra control byte. Concatenated JSON fails it because one value may be spread across several lines, or several values may share one.

MIME Type: What to Actually Send

One fact settles the argument: neither application/jsonl nor application/x-ndjson is registered with IANA. There is no official media type, so the question is not which is correct but which is understood.

First choice for HTTP APIs: application/x-ndjson

Content-Type: application/x-ndjson; charset=utf-8

This is the type real tooling recognizes. Search engines, log pipelines, and streaming HTTP clients have converged on it, so a response labeled this way is far more likely to be handled without special configuration. The x- prefix traditionally marks an unregistered subtype.

Second choice: application/jsonl

Content-Type: application/jsonl; charset=utf-8

What jsonlines.org suggests, with the explicit caveat that the "MIME type may be application/jsonl, but this is not yet standardized". It matches the .jsonl extension, so it suits file downloads and internal services, but less third-party software recognizes it.

Rare and last resort

application/jsonlines
text/x-ndjson
text/plain; charset=utf-8

The first two are unregistered and uncommon: accept them on input, do not send them. text/plain is accurate but uninformative, so use it only when nothing else is accepted. Never send application/json - a strict client will parse the whole body as one document and fail on the second line.

Always include the charset parameter

Whichever type you pick, append ; charset=utf-8. UTF-8 is mandatory for the format, but omitting the parameter leaves the decision to the recipient's default.

File Extensions

.jsonl is primary, .ndjson is equally valid and common in log and search tooling, and .jsonlines appears occasionally. Pick one per project - build scripts and editors key off the extension.

Related Standards

NDJSON is not standardized itself, but it inherits two real standards and is routinely confused with a third.

RFC 8259 - JSON itself

Every line is a JSON text as defined by RFC 8259, so the whole grammar applies per line and nothing is relaxed: no comments, no trailing commas, no single-quoted strings, no unquoted keys, no NaN. It also supplies rules NDJSON inherits silently - object names SHOULD be unique, numbers have no defined precision limit. A parse error is almost always RFC 8259 being violated, not an NDJSON rule, and the error dictionary maps those messages back to the offending construct.

RFC 3629 - UTF-8

Rule 1 points here. RFC 3629 defines UTF-8 as the transformation format of ISO 10646, and is why an NDJSON file needs no encoding declaration.

{"name": "José"}
{"location": "東京"}
{"symbol": "€"}

RFC 7464 - a different format, often confused with NDJSON

RFC 7464 defines JSON Text Sequences, media type application/json-seq, and is often cited as "the standard for NDJSON". It is not. It is a different wire format solving a similar problem, and the only part of this landscape that went through the IETF.

The difference is one byte with large consequences. In RFC 7464 each JSON text is preceded by an ASCII record separator, RS (0x1E), and followed by a line feed. Because that separator marks the boundary, the text between separators may contain newlines, so pretty-printed multi-line records are legal. NDJSON has no separator byte and relies on the newline alone, which is why an NDJSON record must sit on one line. Feed a text sequence to an NDJSON parser and every line fails.

// RFC 7464 json-seq (RS shown as \x1e):
\x1e{"id": 1}\n
\x1e{"id": 2}\n

// NDJSON - no separator byte:
{"id": 1}\n
{"id": 2}\n

What a Conforming Parser Must Accept

A conforming reader splits on \n, ignores whitespace around each value, parses the remainder as a JSON text, and emits one record per line in order. It must not require an outer array, objects, or a trailing newline.

Empty file: valid, zero records

A zero-byte file is conforming NDJSON containing no records, and a parser that throws on it is wrong. An empty result set and a freshly rotated log both look like this.

Single line with no trailing newline: valid

The newline terminates values; it is not a required suffix on the last one. A file whose final byte is } is complete, and its last record must still be emitted. Readers that only flush on \n drop that line.

Trailing newline at end of file: valid and conventional

The specification calls a terminator after the last value "strongly recommended but not required", because it makes generating and concatenating files easier. It does not create a phantom empty record, and a parser must not report one. If it is present it must be the last byte in the file - nothing follows it, not even a second newline.

Blank line mid-file: not valid, commonly tolerated

The specification is explicit that "a blank line is not" a valid value, so one makes the file non-conforming. Most parsers skip them rather than fail, and NDJSON section 3.2 sanctions exactly that - a parser "MAY silently ignore empty lines", provided the behavior is documented and ideally configurable - which is why the problem survives in production. Never write them, and decide deliberately whether you skip or reject.

Byte order mark: strip it

A UTF-8 BOM (U+FEFF, bytes EF BB BF) is not part of any JSON value. RFC 8259 forbids adding one and lets parsers ignore one rather than error, so a BOM makes the first line invalid JSON and whether you find out depends on your library. The symptom is unmistakable: line 1 fails, every other line is fine. Strip it on read; do not emit it.

Duplicate keys within a line: parser-defined

A JSON question, not an NDJSON one. RFC 8259 says object names SHOULD be unique but does not require it, so {"id": 1, "id": 2} is not strictly invalid. Most parsers keep the last occurrence, some the first, strict modes reject the line. Never emit duplicates.

Conformance Checklist

Every item is drawn from the rules above, so a file that passes all eight conforms.

  • Encoding is UTF-8. Confirm it with a tool, not an assumption.
  • No byte order mark. The first byte of the file is the first byte of the first JSON value.
  • Every line parses as JSON on its own. Test lines independently; the file as a whole never parses.
  • No blank lines anywhere, including after the final terminator.
  • Every value sits on exactly one line. No pretty printing; escape newlines inside strings as \n.
  • No commas between lines and no outer brackets. The file is a sequence of values, not an array.
  • Line endings are LF, or CRLF. Both conform; prefer LF, uniformly.
  • Served with a deliberate media type, normally application/x-ndjson; charset=utf-8.

The NDJSON validator checks the structural items in the browser.

The Format as a Grammar

Neither specification publishes a formal grammar. Written in the ABNF style that RFC 8259 uses for JSON itself, the three rules come out as four lines. This is an illustration, not a normative text.

jsonl-text = *( line LF ) [ line ]      ; zero or more terminated lines, last LF optional
line       = ws value ws                ; exactly one JSON value, optional surrounding whitespace
value      = <any JSON value as defined by RFC 8259, with no literal LF inside it>
LF         = %x0A                       ; ws is JSON whitespace other than LF: space, tab, CR

What the grammar allows

An empty file. A file with one line and no final newline. Leading and trailing spaces on a line. A carriage return before the line feed.

What it forbids

A line with no value on it. A value that contains a real line break. Anything between values other than whitespace and one line feed.

What it leaves open

Maximum line length, whether lines share a shape, key order and number precision. Those are decided by your tools and by the platform that reads the file.

Questions About the Definition

Is NDJSON valid JSON?

Each line is valid JSON. The file as a whole is not, unless it has exactly one line. Feeding a multi-line NDJSON file to a standard JSON parser fails at the start of line 2 with an error such as "Extra data" or "Unexpected non-whitespace character after JSON".

What does NDJSON stand for?

JSON Lines. JSON is JavaScript Object Notation, and the L marks that the file is a list of JSON values, one per line. NDJSON stands for Newline Delimited JSON and means the same format.

Can a string inside a record contain a newline?

Yes, as the escape sequence \n. JSON already forbids raw control characters inside strings, so any correct JSON serializer writes the escape for you. A record only breaks when someone builds the line by hand or pretty-prints it.

Is there a maximum line length?

Not in the specification. Limits come from tools: Go's bufio.Scanner stops at 64 KB per line by default, and many platforms cap the size of a single record or of the whole upload. Check the limits of whatever reads your file. The troubleshooting guide covers the common ones.

Does every line need the same keys?

No. The format places no relationship between lines. Tools that load NDJSON into tables do care, so consistent keys and types make a file far easier to use. The best practices guide explains how to keep a dataset consistent.

Is the order of lines meaningful?

The file preserves order, and readers see lines in the order they were written. Whether that order means anything is up to the data. Logs are ordered by time; a shuffled training set is deliberately not. Distributed systems that split a file across workers may not process lines in order, so carry a timestamp or sequence number if order matters.

Who maintains the NDJSON specification?

Nobody in a formal sense. jsonlines.org and the NDJSON specification are short community documents with no standards body behind them. The format has not needed revisions because there is so little of it to revise. The history page traces where it came from.

Learn More About NDJSON

Now that you understand the specification, explore advantages, compare with other formats, and see real-world examples.