ArticleslgStudy

science

JSON streaming

JSON streaming is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand JSON streaming rather than just read about it. In short: JSON streaming refers to communications protocols to delimit JSON objects. These are typically built upon lower-level stream-oriented protocols (such as TCP).

Key takeaways

  • JSON streaming belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect JSON streaming to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of JSON streaming from memory before moving on to harder problems.

Reference excerpt

JSON streaming refers to communications protocols to delimit JSON objects. These are typically built upon lower-level stream-oriented protocols (such as TCP). A streaming JSON protocol is often required to ensure that individual JSON objects are recognized by a client. A server and client often have to agree on the same JSON streaming protocol in order to product and consume events effectively.

Introduction JSON is a popular format for exchanging object data between systems. However, JSON is a non-concatenative protocol (i.e. concatenating two JSON objects does not produce a valid JSON object). JSON IETF RFC 7464 defines a JSON text sequence as JSON texts each preceded by the ASCII record separator character and followed by a line feed.. For use cases like a stock ticker or application log records., it is often convenient to consume individual records as JSON. In these cases there's a need to identify where one JSON encoded object ends and the next begins (a form of framing). There are four common ways to achieve this:

Send the JSON objects formatted without newlines and use a newline as the delimiter. Send the JSON objects concatenated with a record separator control character as the delimiter. Send the JSON objects concatenated with no delimiters and rely on a streaming parser to extract them. Send the JSON objects prefixed with their length and rely on a streaming parser to extract them.

Comparison Line-delimited JSON is compatible with traditional line-oriented tools. Concatenated JSON works with pretty-printed JSON but requires more effort and complexity to parse. It doesn't work well with traditional line-oriented tools. Concatenated JSON streaming is a superset of line-delimited JSON streaming. Length-prefixed JSON works with pretty-printed JSON. It doesn't work well with traditional line-oriented tools, but may offer performance advantages over line-delimited or concatenated streaming. It can also be simpler to parse.

Approaches

Newline-delimited JSON

Two terms for equivalent formats of line-delimited JSON are:

Newline delimited (NDJSON) - The old name was Line delimited JSON (LDJSON). JSON lines (JSONL), that is the current (2025) and most used standard, in Big Data and other applications. Streaming makes use of the fact that the JSON format does not allow return and newline characters within primitive values (in strings those must be escaped as \r and \n, respectively) and that most JSON formatters default to not including any whitespace, including returns and newlines. These features allow the newline character or return and newline character sequence to be used as a delimiter. This example shows two JSON objects (the implicit newline character at the end of each line is not shown):

The use of a newline as a delimiter enables this format to work very well with traditional line-oriented Unix tools. A log file, for example, might look like:

which can be sorted by date, grep for usernames, actions, IP addresses, etc.

Compatibility Line-delimited JSON can be read by a parser that can handle concatenated JSON. Concatenated JSON that contains newlines within a JSON object can't be read by a line-delimited JSON parser. The terms "line-delimited JSON" and "newline-delimited JSON" are often used without clarifying if embedded newlines are supported. In the past the newline delimited JSON specification allowed comments to be embedded if the first two characters of a given line were "//". This could not be used with standard JSON parsers if comments were included. Current version of the specification ("NDJSON - Newline delimited JSON ") no longer includes comments. Concatenated JSON can be converted into line-delimited JSON by a suitable JSON utility such as jq. For example

Record separator-delimited JSON Record separator-delimited JSON streaming allows JSON text sequences to be delimited without the requirement that the JSON formatter exclude whitespace. Since JSON text sequences cannot contain control characters, a record separator character can be used to delimit the sequences. In addition, it is suggested that each JSON text sequence be followed by a line feed character to allow proper handling of top-level JSON objects that are not self delimiting (numbers, true, false, and null). This format is also known as JSON Text Sequences or MIME type application/json-seq, and is formally described in IETF RFC 7464. The example below shows two JSON objects with ␞ representing the record separator control character and ␊ representing the line feed character:

Concatenated JSON Concatenated JSON streaming allows the sender to simply write each JSON object into the stream with no delimiters. It relies on the receiver using a parser that can recognize and emit each JSON object as the terminating character is parsed. Concatenated JSON isn't a new format, it's simply a name for streaming multiple JSON objects without any delimiters. The advantage of this format is that it can handle JSON objects that have been formatted with embedded newline characters, e.g., pretty-printed for human readability. For example, these two inputs are both valid and produce the same output:

Implementations that rely on line-based input may require a newline character after each JSON object in order for the object to be emitted by the parser in a timely manner. (Otherwise the line may remain in the input buffer without being passed to the parser.) This is rarely recognised as an issue because terminating JSON objects with a newline character is very common.

Length-prefixed JSON Length-prefixed or framed JSON streaming allows the sender to explicitly state the length of each message. It relies on the receiver using a parser that can recognize each length n and then read the following n bytes to parse as JSON. The advantage of this format is that it can speed up parsing due to the fact that the exact length of each message is explicitly stated, rather than forcing the parser to search for delimiters. Length-prefixed JSON is also well-suited for TCP applications, where a single "message" may be divided into arbitrary chunks, because the prefixed length tells the parser exactly how many bytes to expect before attempting to parse a JSON string.

This example shows two length-prefixed JSON objects (with each length being the byte-length of the following JSON string):

Applications and tools

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with JSON streaming

Start with the simplest possible case. Write down what JSON streaming claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to JSON streaming before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about JSON streaming ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of JSON streaming

In research
JSON streaming appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses JSON streaming in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
JSON streaming is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data serialization formats, JSON, so understanding it makes those chapters shorter.
In everyday life
Look for JSON streaming outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “JSON streaming” →

How to study JSON streaming in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what JSON streaming means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain JSON streaming out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is JSON streaming in simple terms?

JSON streaming refers to communications protocols to delimit JSON objects. These are typically built upon lower-level stream-oriented protocols (such as TCP).

Why does JSON streaming matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study JSON streaming?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on JSON streaming.

Tags

  • Data serialization formats
  • JSON

Keep exploring