New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-to-csv-export

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-csv-export

Easily generate csv downloads of your json data.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
decreased by-5.43%
Maintainers
1
Weekly downloads
 
Created
Source

⬇️ json-to-csv-export

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

npm package version   npm downloads   code style: prettier

Live Demo

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:

npm i json-to-csv-export

or load from a CDN:

<script src="https://cdn.jsdelivr.net/npm/json-to-csv-export"></script>

Example Usage

// 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

// 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

interface HeaderMapping {
  label: string;
  key: string;
}
#PropertyTypeRequirementDefaultDescription
1data[]requiredarray of objects
2filenamestringoptional"export.csv"The filename. The .csv extention will be added if not included in file name
3delimiterstringoptional","fields separator
4headersstring[] OR
HeaderMapping[]
optionalprovided data object keysList of columns that will be used in the final CSV file. Recommended for large datasets!

Migration from version 1.x to 2.x

migration.md

Contributing

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

Keywords

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc