Skip to content
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.

Introduction

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.

API

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.
  • pathSeparator
  • once

Static methods and properties

Same as Replace:

  • ignore(options) — factory function returning a filter for use in chain().
  • ignore.asStream(options) — returns a Duplex stream (object-mode both sides) for .pipe() usage.
  • ignore.withParser(options) — creates a parser() + ignore() pipeline.
  • ignore.withParserAsStream(options) — same, wrapped as a Duplex stream.

Web Streams

ignore ships in two substrate-specific entries with the same factory shape:

  • Nodestream-json/filters/ignore.js. Has asStream, asWebStream, withParser, withParserAsStream, withParserAsWebStream.
  • Webstream-json/web/filters/ignore.js. Has asWebStream, 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);

Clone this wiki locally