Line Delimited JSON

From Wikipedia, the free encyclopedia
Jump to: navigation, search

A standard for delimiting JSON in stream protocols (such as TCP).


This is a minimal specification for sending and receiving JSON over a stream protocol, such as TCP.

The Line Delimited JSON framing is so simple that no specification had previously been written for this ‘obvious’ way to do it.

Example Output[edit]

(with \r\n line separators)



There is currently no standard for transporting JSON within a stream protocol (primarily plain TCP), apart from Websockets, which is unnecessarily complex for non-browser applications.

There were numerous possibilities for JSON framing, including counted strings and non-ASCII delimiters (DLE STX ETX or Websocket’s 0xFFs).


The primary use case for LDJSON is an unending stream of JSON objects, delivered at variable times, over TCP, where each object needs to be processed as it arrives. e.g. a stream of stock quotes or chat messages.

Philosophy / Requirements[edit]

The specification must be:

  • trivial to implement in multiple popular programming languages
  • flexible enough to handle arbitrary whitespace (pretty-printed JSON)
  • not contain non-printable characters
  • netcat/telnet friendly

Functional Specification[edit]


Each JSON object must be written to the stream followed by the carriage return and newline characters 0x0D0A. The JSON objects may contain newlines, carriage returns and any other permitted whitespace. See for the full spec.

All serialized data must use the UTF8 encoding.


The receiver should handle pretty-printed (multi-line) JSON.

The receiver must accept all common line endings: ‘0x0A’ (Unix), ‘0x0D’ (Mac), ‘0x0D0A’ (Windows).

Trivial Implementation[edit]

A simple implementation is to accumulate received lines. Every time a line ending is encountered, an attempt must be made to parse the accumulated lines into a JSON object.

If the parsing of the accumulated lines is successful, the accumulated lines must be discarded and the parsed object given to the application code.

If the amount of unparsed, accumulated characters exceeds 16MiB the receiver may close the stream. Resource constrained devices may close the stream at a lower threshold, though they must accept at least 1KiB.

Other Implementations[edit]

Alternative, more efficient, implementations are possible using a custom JSON parser.

The reference NodeJS/Javascript implementation will be posted on github shortly.

MIME Type and File Extensions[edit]

When using HTTP/email the MIME type for Line Delimited JSON should be application/x-ldjson (which will hopefully later change to application/ldjson).

When saved in a file, the file extension should be .ldjson or .ldj

Many parsers handle Line Delimited JSON[citation needed], and standard content-type for "streaming JSON" suggests application/json; boundary=NL for the MIME type

Notes and References[edit] "Newline Delimited JSON". Retrieved 2 July 2013. 

chrisdew. "Choice of Transports for JSON over TCP". Retrieved 2 July 2013. 

Ryan, Film Grain. "How We Built Filmgrain, Part 2 of 2". Retrieved 4 July 2013.