-
-
Notifications
You must be signed in to change notification settings - Fork 53
Ignore
Eugene Lazutkin edited this page May 23, 2026
·
9 revisions
Ignore removes matching subobjects from a token stream entirely. It is built on FilterBase and rejects matched values without emitting any replacement tokens.
const {ignore} = require('stream-json/filters/ignore.js');
const {parser} = require('stream-json/parser.js');
const {streamArray} = require('stream-json/streamers/stream-array.js');
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.
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