Guide

How to parse SSE data lines as JSON

ToolboxKit maintainer · Published July 22, 2026 · Updated July 22, 2026

Server-Sent Events are a text stream. A captured response can contain event metadata, JSON-bearing data: lines, blank separators, and a terminal marker. The complete capture is therefore not one JSON document.

Representative input

event: message
data: {"id":1,"status":"started"}

data: {bad}
data: {"id":1,"status":"finished"}
data: [DONE]

Deterministic parsing rules

  1. Read only lines whose first non-space text is data:.
  2. Remove the field prefix and leading field whitespace.
  3. Ignore the exact terminal payload [DONE].
  4. Parse each remaining payload independently as JSON.
  5. Keep valid records and report every malformed payload with its original line number.

The example produces two records and one warning for line 4. Partial recovery is useful only when skipped data remains visible.

Expected output

[
  {"id": 1, "status": "started"},
  {"id": 1, "status": "finished"}
]

If every data: payload is malformed, the extractor returns an explicit error instead of treating unrelated lines as a different format.

Boundary of this tool

This workflow parses one JSON value per captured data: line. It does not implement network reconnection, SSE event dispatch, multi-line field concatenation, or browser EventSource behavior. It is for inspecting copied debugging text.

Privacy and use

Stream captures may contain prompts, account identifiers, tokens, or model output. Redact the sample first. Parsing runs locally and does not require sending the captured stream to an application backend.

Extract SSE JSON records