json2csv

Convert JSON arrays into CSV strings and files with configurable fields, formatters, and streaming parsers for Node.js.

Library
npm
v6.0.0-alpha.2
2,719stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
49/100Fair
Development Activity0
Maintenance20
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture78
Code Quality68
Innovation74
Learning Curve75

json2csv is the original Node.js library for converting JSON data into CSV output, published under the plain npm name json2csv since 2012. It exposes a family of parser classes — a synchronous Parser, a promise-based AsyncParser, a StreamParser for streaming input, and a Transform stream for piping — along with a bundled CLI binary for converting files from the command line without writing any code.

The project has been in maintenance mode since 2023, when its maintainers split the codebase into smaller scoped packages (@json2csv/plainjs, @json2csv/node, @json2csv/whatwg, @json2csv/cli, and others) that now receive active development. This original json2csv package remains available on npm — at 6.0.0-alpha.2 — and continues to see wide adoption in existing Node.js projects (over 2 million weekly downloads) thanks to its stable, dependency-light API for field selection, custom formatters, and value transforms like flatten and unwind.

What You Get

  • A synchronous Parser class for converting in-memory JSON arrays to CSV strings in one call
  • An AsyncParser and StreamParser for processing large or streaming JSON payloads without loading everything into memory
  • A Transform stream implementation for piping JSON straight into a writable CSV stream
  • Built-in flatten and unwind transforms for handling nested objects and arrays
  • A bundled json2csv CLI binary for converting JSON files to CSV from the terminal, with pretty-printed table output
  • Per-type formatters (string, number, symbol, object) that control how values are escaped and stringified in each cell

Common Use Cases

  • Exporting API or database query results as downloadable CSV reports for end users
  • Converting NDJSON log files into CSV for spreadsheet analysis via the CLI
  • Streaming large JSON datasets to CSV without buffering the full array in memory
  • Flattening nested JSON records (e.g., orders with line items) into flat CSV rows using the unwind transform

Under The Hood

Architecture JSON2CSVBase is an abstract class centralizing options normalization, field-to-value derivation, delimiter/EOL handling, and per-cell formatting dispatch keyed by typeof value; it’s extended by JSON2CSVParser (sync), JSON2CSVAsyncParser, JSON2CSVStreamParser, and JSON2CSVTransform (a Node Transform stream), each of which implements only its own parse/push control flow while inheriting the shared row/cell processing contract. Formatters and transforms (flatten, unwind) are injected as plain functions rather than subclassed, keeping extension points functional instead of object-oriented. The entry point lib/json2csv.js is a thin barrel file re-exporting the four parser classes plus convenience parse/parseAsync wrappers, while bin/json2csv.js is a separate Commander-based CLI that requires the same library and adds file I/O, ndjson parsing, and table printing. Because none of the parser variants reimplement per-cell formatting independently, JSON2CSVBase’s processRow/processCell/processValue methods are the single point that all four variants and the CLI depend on.

Tech Stack Plain CommonJS Node.js with no TypeScript and no framework. Dependencies are deliberately minimal — @streamparser/json for the streaming parser, commander for CLI argument parsing, and lodash.get for safe nested-path access rather than full lodash. Rollup (with babel, commonjs, and node-resolve plugins) builds ESM and UMD browser bundles alongside the CommonJS lib/ used directly by Node, wired through package.json’s main/module/browser fields. Tests run on tape with tap-spec output and nyc coverage; releases use standard-version, and docs are published via docpress + gh-pages. CI runs on Travis, and linting uses a bare eslint:recommended config.

Code Quality Tests are reasonably thorough — dedicated fixture-driven suites exist per parser class (Parser, AsyncParser, AsyncParserInMemory, StreamParser, Transform, CLI, ndjson parsing), comparing output against golden JSON/CSV fixtures rather than just smoke-testing. Error handling is minimal and largely implicit: invalid fields configs and empty-data-without-fields cases throw plain, generic Errors, with no custom error hierarchy or typed errors, and formatter functions generally assume well-typed input without guarding. There is no static type checking — formatter dispatch relies on runtime typeof checks. Naming is consistent across the class hierarchy, and CI exists via Travis, though the project itself documents that it is no longer actively maintained past v6.0.0-alpha.2.

API Design The base-class-plus-functional-extension-points design keeps the everyday API small — most consumers only ever call new Parser(opts).parse(data) or the parse/parseAsync convenience exports — while power users can layer custom formatters and transforms without touching the parser classes. The fields option’s flexible shorthand (a plain string path, {label, value: path}, or {label, value: fn}) minimizes boilerplate for the common case while still supporting fully custom column derivation. Documentation is extensive for a library of this age, with runnable examples covering nearly every option combination and a hosted docs site linked from the README. The main friction is external rather than structural: the top-level README is entirely a deprecation notice pointing at a successor project, so newcomers have to look past it into docs/ or the npm listing to find working examples, even though the underlying API remains solid and the package still sees heavy download volume.

Used by 6 apps in this directory

JavaScript
83%
Other

Countly

Analytics · Marketing

5,896

Privacy-first, self-hosted analytics and customer engagement platform with full data ownership, GDPR compliance, and AI-powered insights across mobile, web, desktop, and IoT.

View details
95
Repo Health
82
Technical
65
Dependency
Built with
JavaScript83%
Updated 3 days ago
TypeScript
81%
Other

Directus

CMS · Low Code Platforms

37,783

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript81%
Vue18%
Updated 3 days ago
TypeScript
97%
Other

GrowthBook

Developer Tools · Analytics · Monitoring

8,299

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,965

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
85
Repo Health
67
Technical
67
Dependency
Built with
TypeScript95%
Updated 1 weeks ago
TypeScript
94%
Apache 2.0

OneUptime

Monitoring

7,563

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
90
Repo Health
81
Technical
65
Dependency
Built with
TypeScript94%
Updated today
JavaScript
63%
AGPL 3.0

overleaf

Collaboration · Productivity

18,090

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
82
Repo Health
80
Technical
62
Dependency
Built with
JavaScript63%
TypeScript29%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search