# json-to-csv-export

> Easily generate csv downloads of your json data.

Latest version **3.1.3** (published 2025-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-to-csv-export
pnpm add json-to-csv-export
yarn add json-to-csv-export
bun add json-to-csv-export
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.1.3 |
| Published | 2025-10-09 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.17.0 |
| Dependencies | 0 |
| Unpacked size | 61.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 89 |
| Author | Coston Perkins |
| Maintainers | coston |
| Keywords | json, csv, download, web |

## Links

- npm: https://www.npmjs.com/package/json-to-csv-export
- Repository: https://github.com/coston/json-to-csv-export
- Issues: https://github.com/coston/json-to-csv-export/issues
- npm.io page: https://npm.io/package/json-to-csv-export

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.1.3 (latest) — 2025-10-09
- 2.2.0-0 (next) — 2023-08-07
- 3.1.2 — 2025-05-06
- 3.1.1 — 2025-05-06
- 3.1.0 — 2024-10-02
- 3.0.1 — 2024-08-09
- 3.0.0 — 2024-07-31
- 2.1.1 — 2022-12-05
- 2.1.0 — 2022-10-28
- 2.0.2 — 2022-09-14
- 2.0.2-0 — 2022-09-14
- 2.0.1 — 2022-09-14
- 2.0.0 — 2022-09-13
- 1.1.2 — 2022-08-30
- 1.1.1 — 2022-08-07
- … 4 more at https://npm.io/package/json-to-csv-export/versions

## README

# ⬇️ json-to-csv-export

A function to easily generate csv downloads of your json data. ✨

[![npm package version](https://badge.fury.io/js/json-to-csv-export.svg)](https://www.npmjs.com/package/json-to-csv-export)
&nbsp;
[![npm downloads](https://img.shields.io/npm/dm/json-to-csv-export.svg)](https://www.npmjs.com/package/json-to-csv-export)
&nbsp;
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)

## Live Demo

[https://json-to-csv-export.coston.io](https://json-to-csv-export.coston.io)

## Features

- Create a csv download from json data
- Lightweight
- Easy to use
- Optional filename
- Optional header names

## Install

Install with npm:

```sh
npm i json-to-csv-export
```

## Example Usage

```jsx
// import jsonToCsvExport from "json-to-csv-export";

() => {
  const mockData = [
    {
      ID: 1,
      "First Name": "Sarajane",
      "Last Name": "Wheatman",
      Email: "swheatman0@google.nl",
      Language: "Zulu",
      "IP Address": "40.98.252.240",
    },
    {
      ID: 2,
      "First Name": "Linell",
      "Last Name": "Humpherston",
      Email: "lhumpherston1@google.com.br",
      Language: "Czech",
      "IP Address": "82.225.151.150",
    },
  ];

  return (
    <button onClick={() => jsonToCsvExport({ data: mockData })}>
      Download Data
    </button>
  );
};
```

## Example with Header mapping

```jsx
// import jsonToCsvExport from "json-to-csv-export";
() => {
  const mockData = [
    {
      id: 1,
      firstName: "Sarajane",
      lastName: "Wheatman",
      email: "swheatman0@google.nl",
      language: "Zulu",
      ip: "40.98.252.240",
    },
    {
      id: 2,
      firstName: "Linell",
      lastName: "Humpherston",
      email: "lhumpherston1@google.com.br",
      language: "Czech",
      ip: "82.225.151.150",
    },
  ];

  const headers = [
    { key: "id", label: "Identifier" },
    { key: "firstName", label: "First Name" },
    { key: "lastName", label: "Last Name" },
    { key: "email", label: "Email Address" },
    { key: "language", label: "Language" },
    { key: "ip", label: "IP Address" },
  ];

  return (
    <button onClick={() => jsonToCsvExport({ data: mockData, headers })}>
      Download Data
    </button>
  );
};
```

## Properties

```typescript
interface HeaderMapping {
  label: string;
  key: string;
}
```

| #   | Property  | Type                          | Requirement | Default      | Description                                                                 |
| --- | --------- | ----------------------------- | ----------- | ------------ | --------------------------------------------------------------------------- |
| 1   | data      | `Record<string, any>[]`       | required    |              | array of objects                                                            |
| 2   | filename  | `string`                      | optional    | "export.csv" | The filename. The .csv extention will be added if not included in file name |
| 3   | delimiter | `string`                      | optional    | ","          | fields separator                                                            |
| 4   | headers   | `string[]`, `HeaderMapping[]` | optional    |              | provided data object keys                                                   |

## Migration from version 1.x to 2.x

[migration.md](migration.md)

## Contributing

Please help provide good data faster! Submit any issues and/or make a pull request!

---
_Source: https://npm.io/package/json-to-csv-export · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
