json2csv

Flexible conversion between JSON and CSV

MIT License

Downloads
2.6M
Stars
303
Committers
80

json2csv

Fast and highly configurable JSON to CSV converter.

Features

  • Fast and lightweight
  • Support for standard JSON as well as NDJSON
  • Scalable to infinitely large datasets (using stream processing)
  • Advanced data selection (automatic field discovery, underscore-like selectors, custom data getters, default values for missing fields, ...)
  • Support for custom input data transformation
  • Support for custom csv cell formatting.
  • Highly customizable (supporting custom quotation marks, delimiters, eol values, etc.)
  • Automatic escaping (preserving new lines, quotes, etc.)
  • Optional headers
  • Unicode encoding support
  • Pretty printing in table format to stdout

json2csv ecosystem

There are multiple flavours of json2csv:

  • The Plainjs package includes:
    • Parser: Pure Javascript synchronous parser. High-performant and runs both node.js and the browser. Its the fastest but loads both the JSON and the resulting CSV in memory, and block the event loop while processing. Not recommended unless the JSON data is small.
    • Stream Parser: Pure Javascript stream parser. High-performant and runs both node.js and the browser. It keeps a consistent memory footprint and doesn't block the event loop. It's the base of all other parsers. Recommended to build your own parser.
  • The Node packages includes:
    • Node Transform: Wraps the Stream Parser in a Node.js Transform Stream. Recommended for Node.js users using stream.
    • Node Async Parser: Wraps the Node Transform to offer a friendly promise-based API similar to the synchronous Parser. Recommended for Node.js users that want a higher abstraction level.
  • The WHATWG package includes:
    • WHATWG Transform Stream: Wraps the Stream Parser in a WHATWG Transform Stream. Recommended for browser users using web streams.
    • WHATWG Async Parser: Wraps the WHATWG Transform Stream to offer a friendly promise-based API similar to the synchronous Parser. Recommended for browser users that want a higher abstraction level.
  • The CLI package includes:
    • CLI: Makes the node.js interfaces accesible through the command line. Recommended from CLI (sh/bash/zsh/...) users and CLI scripts.

And a couple of libraries that enable additional configurations:

  • The Transforms package includes the built-in transforms for json2csv (unwind and flatten) allowing the using to transform data before is parsed (See docs).
  • The Formatters package includes the built-in formatters for json2csv (one for each data type, an excel-specific one, etc.). Formatters convert JSON data types into CSV-compatible strings (See docs).

Documentation

See https://juanjodiaz.github.io/json2csv.

License

See LICENSE.md.