Skip to content
Eugene Lazutkin edited this page Jul 29, 2026 · 10 revisions

Signature: tokenstokens

Ignore removes matching subobjects from a token stream entirely. It is built on FilterBase and rejects matched values without emitting any replacement tokens.

Introduction

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.

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