@ooneex/json reads a JSON file as a stream and yields each top-level object through an async generator, so you can process large arrays without loading the whole file into memory. The Json class also lets you skip records by pattern and write the results straight out to YAML or CSV.
Installation
Install the package with Bun.Usage
Construct aJson instance with a file path, optionally typing the records, then iterate with for await. Each top-level object (or array element) is parsed and yielded one at a time.
Ignoring records
Pass anignore map of field-to-RegExp. Any record whose field matches its pattern is skipped during iteration.
Converting to YAML or CSV
toYaml and toCsv consume the same stream and write to an output path. toCsv requires the headers to emit and a separator; both accept the same ignore filter.
json.getPath().
When to use it
- Processing large JSON arrays that won’t fit comfortably in memory —
load()streams one record at a time. - Filtering out unwanted records on the fly with the
ignoreregex map. - Exporting JSON data to YAML or CSV without a separate serialization library.
- Building ETL-style pipelines where you transform each record as it streams in.
JSON.parse() is simpler when the whole document already fits in memory.