You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ stream-json/
109
109
-**Keep `.js` and `.d.ts` files in sync** for all modules under `src/`.
110
110
-**Token-based architecture.** The parser produces a stream of `{name, value}` tokens. All filters, streamers, and utilities operate on this token protocol.
111
111
-**Backpressure must be handled correctly.** All stream components rely on Node.js stream infrastructure via `stream-chain`.
112
-
-**Intended input is data the user owns or trusts** (dumps, exports, logs). The library is not designed for hostile input; docs say so, and code changes are not hardened against adversarial JSON beyond `JSON.parse` parity (`__proto__` becomes an own property) and the filters' `maxDepth` guard.
112
+
-**Intended input is data the user owns or trusts** (dumps, exports, logs). The library is not designed for hostile input; docs say so, and code changes are not hardened against adversarial JSON or JSONC beyond `JSON.parse` parity (`__proto__` becomes an own property) and the filters' `maxDepth` guard.
113
113
114
114
## Architecture
115
115
@@ -136,7 +136,7 @@ stream-json/
136
136
-`withParser(fn, options)` creates a `gen(parser(options), fn(options))` pipeline — the most common pattern.
137
137
- Most components export `.withParser(options)` and `.withParserAsStream(options)` static methods.
138
138
-**JSONL** (**deprecated — slated for removal in a future major**): `jsonl/parser.js` and `jsonl/stringer.js` are thin re-exports of stream-chain's JSONL (the parser API was absorbed into stream-chain). The Node/Web wrappers delegate `.asStream`/`.asWebStream` to stream-chain's bundled `stream-chain/node/jsonl/*` and `stream-chain/web/jsonl/*` factories. Use stream-chain's JSONL directly. Rationale: stream-json is a JSON _token_ library; JSONL yields whole objects per line and belongs in stream-chain with the other substrate components.
139
-
-**JSONC**: `jsonc/parser.js`, `jsonc/stringer.js`, and `jsonc/verifier.js` for JSON with Comments. Extend the standard parser/stringer/verifier (same `charCodeAt` tokenizer/validator) with `whitespace`/`comment`/`comma` tokens, trailing comma support, and `streamWhitespace`/`streamComments`/`streamCommas` (parser) plus `useCommas` (stringer) options. `streamCommas` + `useCommas` give byte-faithful comma round-trips (incl. trailing commas) for streaming edits; both default off. Raw inner exports: `jsoncParser`, `jsoncVerifier`.
139
+
-**JSONC**: `jsonc/parser.js`, `jsonc/stringer.js`, and `jsonc/verifier.js` for JSON with Comments. Extend the standard parser/stringer/verifier (same `charCodeAt` tokenizer/validator) with `whitespace` / comment / `comma` tokens, trailing comma support, and `streamWhitespace`/`streamComments`/`packComments`/`streamCommas` (parser) plus `useCommentValues`/`useCommas` (stringer) options. Comments mirror strings (`startComment` / `commentChunk` / `endComment`, packed `commentValue`) and their scan resumes across chunks — never rescan an accumulated comment from its start. `streamCommas` + `useCommas` give byte-faithful comma round-trips (incl. trailing commas) for streaming edits; both default off. Raw inner exports: `jsoncParser`, `jsoncVerifier`.
140
140
-**File I/O (Node-only)** (`src/file/`, since 3.3.0): `parseFile()` is an input-edge stage that turns a file path into a token stream (`gen(asyncBlockReader, jsonParser)`); `stringerToFile(path)` is the symmetric output-edge sink (`gen(stringer, asyncBlockWriter)`); `verifyFile(path)` is a standalone async validator returning `Promise<void>`. JSONC variants under `src/file/jsonc/`. NOT mirrored in `core/` or `web/` because they use `node:fs/promises`. Compose with `pipe(...)` (one-shot driver with auto-flush — `gen(...)` alone doesn't flush, so `stringerToFile` wouldn't close the file) and `drain(asyncGen)` (returns the last yielded value or `undefined`). Both helpers live in `core/utils/` (web-safe, no Node deps).
141
141
-**Substrate split**: `src/core/` holds the pure substrate-agnostic factories (no Node-stream imports — checked by `tests/node/test-browser-safe.js` which scans `.d.ts` for `node:*` imports and `extends DuplexOptions`). `src/` (Node entry) attaches `.asStream` (Node Duplex) and `.asWebStream` (Web `{readable, writable}` pair). `src/web/` attaches only `.asWebStream` and `.withParserAsWebStream`, with no Node-stream imports — safe for browser bundles. The `chain` from `stream-chain` (Node) or `stream-chain/web` (Web) auto-wraps the pure flushables on both substrates, so user-facing pipeline code is identical.
Copy file name to clipboardExpand all lines: ARCHITECTURE.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,8 +194,8 @@ The item shape is the exported `KeyedValue<K, T>` type (`core/streamers/stream-b
194
194
195
195
### JSONC support
196
196
197
-
-`jsonc/parser.js` — the `charCodeAt` tokenizer of `parser.js` extended with `//` and `/* */` comments, trailing commas, and optional `whitespace`/`comment`/`comma` tokens (raw inner export `jsoncParser`). Options: `streamWhitespace` (default: true), `streamComments` (default: true), `streamCommas` (default: false — emit a valueless `comma` token at every comma's position; the comma byte is already buffered, so emission needs no lookahead and is fully resumable). All standard parser options are supported.
198
-
-`jsonc/stringer.js` — fork of `stringer.js` that passes `whitespace` and `comment` tokens through verbatim. Option `useCommas` (default: false) renders streamed `comma` tokens as `,` (a separator is still auto-inserted before a value when no `comma` token preceded it, so output stays valid even if commas were dropped upstream) — `streamCommas` + `useCommas` give byte-faithful comma round-trips, incl. trailing commas. All standard stringer options are supported.
197
+
-`jsonc/parser.js` — the `charCodeAt` tokenizer of `parser.js` extended with `//` and `/* */` comments, trailing commas, and optional `whitespace` / comment / `comma` tokens (raw inner export `jsoncParser`). Comments mirror strings — streamed `startComment` / `commentChunk` / `endComment` and packed `commentValue`; the comment scan resumes across input chunks, so a comment of any length costs linear time (GHSA-hqr4-qq8f-hg3x). Options: `streamWhitespace` (default: true), `streamComments` (default: true), `packComments` (default: true), `streamCommas` (default: false — emit a valueless `comma` token at every comma's position; the comma byte is already buffered, so emission needs no lookahead and is fully resumable). All standard parser options are supported.
198
+
-`jsonc/stringer.js` — fork of `stringer.js` that passes `whitespace` and comment tokens through verbatim (`useCommentValues` selects the packed form). Option `useCommas` (default: false) renders streamed `comma` tokens as `,` (a separator is still auto-inserted before a value when no `comma` token preceded it, so output stays valid even if commas were dropped upstream) — `streamCommas` + `useCommas` give byte-faithful comma round-trips, incl. trailing commas. All standard stringer options are supported.
199
199
-`jsonc/verifier.js` — the `charCodeAt` validator of `utils/verifier.js` extended to accept comments and trailing commas (raw inner export `jsoncVerifier`). Reports error offset, line, and position for invalid JSONC.
200
200
- Downstream compatibility: all existing filters, streamers, and utilities ignore unknown token types, so they work with JSONC parser output unmodified.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Why it might be for you:
16
16
17
17
## Intended input
18
18
19
-
`stream-json` is built for data you own or trust — database dumps, exports, logs, and files produced by your own systems. It is not designed for hostile input: do not feed it JSON from the open internet or from untrusted users. Untrusted JSON needs validation of its own before it reaches a pipeline.
19
+
`stream-json` is built for data you own or trust — database dumps, exports, logs, and files produced by your own systems. It is not designed for hostile input: do not feed it JSON or JSONC from the open internet or from untrusted users. Untrusted JSON needs validation of its own before it reaches a pipeline.
Copy file name to clipboardExpand all lines: llms-full.txt
+9-7Lines changed: 9 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
- Proper backpressure handling via Node.js stream infrastructure
15
15
- Works with `stream-chain` for pipeline composition
16
16
17
-
**Intended input:** data you own or trust — database dumps, exports, logs, files produced by your own systems. `stream-json` is not designed for hostile input: do not feed it JSON from the open internet or from untrusted users; untrusted JSON needs validation of its own before it reaches a pipeline.
17
+
**Intended input:** data you own or trust — database dumps, exports, logs, files produced by your own systems. `stream-json` is not designed for hostile input: do not feed it JSON or JSONC from the open internet or from untrusted users; untrusted JSON needs validation of its own before it reaches a pipeline.
18
18
19
19
## Quick start
20
20
@@ -810,7 +810,7 @@ for await (const chunk of ts.readable) console.log(chunk);
810
810
811
811
### jsonc/Parser
812
812
813
-
Streaming JSONC (JSON with Comments) parser. Uses the same `charCodeAt` tokenizer as the standard parser, extended with `//` and `/* */` comments, trailing commas, and optional `whitespace`/`comment`/`comma` tokens. Has `asStream` (Node Duplex) and `asWebStream` (Web pair). Browser-safe Web-only entry: `stream-json/web/jsonc/parser.js`.
813
+
Streaming JSONC (JSON with Comments) parser. Uses the same `charCodeAt` tokenizer as the standard parser, extended with `//` and `/* */` comments, trailing commas, and optional `whitespace` / comment / `comma` tokens. Comments mirror strings: streamed as `startComment` / `commentChunk` / `endComment` (resumable across input chunks — linear time, constant memory without packing) and packed as `commentValue`. Has `asStream` (Node Duplex) and `asWebStream` (Web pair). Browser-safe Web-only entry: `stream-json/web/jsonc/parser.js`.
814
814
815
815
Static methods:
816
816
- `jsoncParser(options)` — factory function returning a composable function for `chain()`.
@@ -820,13 +820,15 @@ Static methods:
820
820
821
821
Options (in addition to all standard parser options):
- `packComments` (boolean, default: true) — emit `commentValue` tokens holding the whole comment. Both off: comments are consumed silently.
824
825
- `streamCommas` (boolean, default: false) — emit a valueless `comma` token at the position of every comma (separator or trailing). For faithful round-trip editing: pair with the stringer's `useCommas` to reproduce comma placement (incl. trailing commas) exactly. No lookahead — the comma is already buffered when seen, so emission is fully resumable.
- `{name: 'startComment'}`, `{name: 'commentChunk', value: '...'}`, `{name: 'endComment'}` — a comment in chunks (delimiters included; a chunk may end anywhere).
JSONC stringer that passes `whitespace` and `comment` tokens through verbatim. All other tokens are handled identically to the standard stringer. Has `asStream` (Node Duplex) and `asWebStream` (Web pair). Browser-safe Web-only entry: `stream-json/web/jsonc/stringer.js`.
859
+
JSONC stringer that passes `whitespace` and comment tokens through verbatim — comments from `commentChunk`s by default, or from `commentValue` with `useCommentValues` (default: false). All other tokens are handled identically to the standard stringer. Has `asStream` (Node Duplex) and `asWebStream` (Web pair). Browser-safe Web-only entry: `stream-json/web/jsonc/stringer.js`.
858
860
859
861
Static methods:
860
862
- `jsoncStringer(options)` — factory function returning a flushable function for `chain()`.
Copy file name to clipboardExpand all lines: llms.txt
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
> Micro-library of Node.js stream components for creating custom JSON processing pipelines with a minimal memory footprint. Parse JSON files far exceeding available memory using a SAX-inspired streaming token API. One dependency: `stream-chain`.
4
4
5
-
**Intended input:** data you own or trust (database dumps, exports, logs, your own systems' files). Not designed for hostile input — do not feed it JSON from the open internet or from untrusted users; validate untrusted JSON before it reaches a pipeline.
5
+
**Intended input:** data you own or trust (database dumps, exports, logs, your own systems' files). Not designed for hostile input — do not feed it JSON or JSONC from the open internet or from untrusted users; validate untrusted JSON before it reaches a pipeline.
- **`jsonc/parser(options)`** — JSONC parser (JSON with Comments). Same `charCodeAt` tokenizer as the standard parser, extended with `//` and `/* */` comments, trailing commas, and `whitespace` / `comment` / `comma` tokens.
194
-
- Extra options: `streamWhitespace` (default: true), `streamComments` (default: true), `streamCommas` (default: false — emit a valueless `comma` token at every comma, separator or trailing, for faithful round-trip editing).
193
+
- **`jsonc/parser(options)`** — JSONC parser (JSON with Comments). Same `charCodeAt` tokenizer as the standard parser, extended with `//` and `/* */` comments, trailing commas, and `whitespace` / comment / `comma` tokens. Comments mirror strings: streamed as `startComment` / `commentChunk` / `endComment` (resumable across input chunks, linear time) and packed as `commentValue`.
194
+
- Extra options: `streamWhitespace` (default: true), `streamComments` (default: true — the streamed form), `packComments` (default: true — `commentValue`; both off consumes comments silently), `streamCommas` (default: false — emit a valueless `comma` token at every comma, separator or trailing, for faithful round-trip editing).
195
195
- All standard parser options are supported.
196
-
- **`jsonc/stringer(options)`** — JSONC stringer. Passes `whitespace` and `comment` tokens through verbatim. Extra option: `useCommas` (default: false — render streamed `comma` tokens as `,`, auto-inserting a separator only when no comma token arrived, so output stays valid even if commas were dropped upstream).
196
+
- **`jsonc/stringer(options)`** — JSONC stringer. Passes `whitespace` and comment tokens through verbatim (comments from `commentChunk`s, or from `commentValue` with `useCommentValues`). Extra options: `useCommentValues` (default: false), `useCommas` (default: false — render streamed `comma` tokens as `,`, auto-inserting a separator only when no comma token arrived, so output stays valid even if commas were dropped upstream).
197
197
- **`jsonc/verifier(options)`** — JSONC validator. Same `charCodeAt` validator as `Verifier`, accepting comments and trailing commas. Reports exact error position.
0 commit comments