liveBook · Manning

Newline-delimited JSON

As explained in Spring AI in Action

Newline-delimited JSON is a format in which each line contains a separate JSON value, allowing a sequence of values to be transmitted incrementally.

Newline-delimited JSON (NDJSON) streams a sequence of JSON values without prefixing each streamed item with data:. In a Spring endpoint, changing produces to application/ndjson preserves incremental delivery while simplifying client handling. section 3.4.3

Account for these implementation details when testing NDJSON streaming:

  • Enable HTTPie streaming explicitly with --stream, because HTTPie does not infer streaming from application/ndjson. section 3.4.3
  • Expect HTTPie to buffer streamed words until it gathers a complete line. section 3.4.3
  • Avoid combining token streaming with output conversion when the final JSON document must remain complete before parsing. section 3.4.3

Streaming an ask endpoint

A controller can declare @PostMapping(path="/ask", produces="application/ndjson") and return a reactive Flux<String>. Testing with HTTPie requires --stream; the response arrives incrementally rather than as one completed document.

How Spring AI in Action covers it

How deep it goes
Explains MIME configuration, client testing, line buffering, and the limitation of combining streaming with JSON output conversion.
Examples
Demonstrates a board-game question endpoint returning streamed answers and tests it with HTTPie.
What you can do after
Operate/configure a Spring endpoint for NDJSON streaming and test it correctly with HTTPie.
How it connects
Connects NDJSON with HTTP streaming, MIME types, HTTPie, reactive Flux, and JSON output conversion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.