-
-
Notifications
You must be signed in to change notification settings - Fork 53
Ignore
Signature: tokens → tokens
Ignore removes matching subobjects from a token stream entirely. It is built on FilterBase and rejects matched values without emitting any replacement tokens.
import {ignore} from 'stream-json/filters/ignore.js';
import {parser} from 'stream-json/parser.js';
import {streamArray} from 'stream-json/streamers/stream-array.js';
import chain from 'stream-chain';
import fs from 'node:fs';
const pipeline = chain([
fs.createReadStream('sample.json'),
parser(), // packs keys by default, otherwise {packKeys: true}
ignore({filter: /\bmeta\b/i}),
streamArray()
]);
pipeline.on('data', data => console.log(data));The upstream must produce packed keys (keyValue tokens) for this filter to work. See Replace for the anchoring caveats of regexp filters like /\bmeta\b/i — it matches at any depth and inside hyphenated keys.
ignore is built on FilterBase. See Replace for the closely related filter that substitutes values instead of removing them.
Options:
-
filter- If it returns a truthy value, the current object is removed completely with all its possible subobjects.
- It is called only for the following tokens:
startObject,startArray,startString,startNumber,stringValue,numberValue,nullValue,trueValue,falseValue.
pathSeparatoronce
Same as Replace:
-
ignore(options)— factory function returning a filter for use inchain(). -
ignore.asStream(options)— returns aDuplexstream (object-mode both sides) for.pipe()usage. -
ignore.withParser(options)— creates aparser() + ignore()pipeline. -
ignore.withParserAsStream(options)— same, wrapped as a Duplex stream.
ignore ships in two substrate-specific entries with the same factory shape:
-
Node —
stream-json/filters/ignore.js. HasasStream,asWebStream,withParser,withParserAsStream,withParserAsWebStream. -
Web —
stream-json/web/filters/ignore.js. HasasWebStream,withParser,withParserAsWebStream. Pulls in no Node-stream imports.
Both factories return the same flushable, so chain on either substrate auto-wraps it. Use chain from stream-chain on Node and from stream-chain/web on Web.
// Web
import {chain} from 'stream-chain/web';
import {parser} from 'stream-json/web/parser.js';
import {ignore} from 'stream-json/web/filters/ignore.js';
import {streamArray} from 'stream-json/web/streamers/stream-array.js';
const pipeline = chain([source, parser.asWebStream(), ignore({filter: /\bmeta\b/i}), streamArray()]);
for await (const item of pipeline.readable) console.log(item);Start here
Core
Filters
Streamers
Essentials
Utilities
File I/O (Node-only)
JSONC
JSONL (use stream-chain)
Reference
Built on stream-chain