Line Delimited JSON

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

Line Delimited JSON is 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.

An important use case is processing a large number of JSON objects where the receiver of the data should not have to receive every single byte before it can begin decoding it. The processing time and memory usage of a JSON parser trying to parse a multi-gigabyte (or larger) string is often prohibitive. Thus, a "properly" encoded JSON list of millions of lines is not a practical way to pass and parse data.

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]

Software that supports Line Delimited JSON[edit]


As of version 9.2 Postgresql has a function called row_to_json. In addition postgresql supports JSON as a field type, so this may output nested components in much the same way as MongoDB and other nosql databases.

   vine@ubuntu:~$ echo 'select row_to_json(article) from article;' | sudo -u postgres psql—tuples-only


An example [1] of command line tools for manipulating JSON lines in much the same way that grep, Sort (Unix) and other *NIX tools manipulate CSV.


sed for JSON, implemented in C and compiled to a standalone binary. [2]


This is a shell-in-a-browser that has pipelines made up from objects [3].


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.


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,[1] and standard content-type for "streaming JSON" suggests application/json; boundary=NL for the MIME type

Notes and References[edit]

  1. ^ "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. 

"row_to_json". Retrieved 6 October 2014.