# Reading JSON Lines without losing records

Line boundaries, UTF-8, blank lines and a final record without a newline.

Category: DATA FORMATS
Canonical: https://fieldnotesarchive.org/wiki/json-lines-streams

JSON Lines stores one JSON value on each line. It is useful for logs and datasets that are processed incrementally. A value can be an object, an array or a scalar; applications often choose objects for consistency.

## Read records, not chunks

A network chunk is not a record. A chunk can end halfway through a line or a UTF-8 character. Decode incrementally, retain the unfinished line, and parse only complete lines. At end of input, process any remaining text.

```text
{"id":1,"status":"pending"}
{"id":2,"status":"complete"}
```

## Make failure visible

A blank line is not a JSON value. Decide whether to reject it or skip it, and document that choice. Report a line number for malformed records rather than silently dropping them. Set a maximum record size so an unfinished line cannot consume unlimited memory.

## Small verification set

- A record split over two chunks.
- A multibyte character split over two chunks.
- A file with no trailing newline.
- A blank line and a malformed value.
- A record exceeding the configured size limit.
