@ceyhuncicek/jsontocsv
v1.1.0
Published
A Node.js utility to convert JSON files to CSV format
Maintainers
Readme
JSON to CSV Converter
A simple Node.js utility to convert JSON files to CSV format.
Installation
Using npx (Recommended)
No installation required! Use directly with npx:
npx @ceyhuncicek/jsontocsv <input-json-file> <output-csv-file>Local Installation
npm installUsage
Using npx (No Installation Required)
npx @ceyhuncicek/jsontocsv data.json output.csvThis will automatically download and run the latest version without requiring local installation.
Command Line (Local Installation)
node jsonToCsv.js <input-json-file> <output-csv-file>Example:
node jsonToCsv.js data.json output.csvProgrammatic Usage
const convertJsonToCsv = require("./jsonToCsv");
const jsonData = [
{ name: "John", age: 30 },
{ name: "Jane", age: 25 },
];
convertJsonToCsv(jsonData, "output.csv")
.then(() => console.log("Conversion complete"))
.catch((error) => console.error("Error:", error));Input Format
The input JSON should be either:
- An array of objects
- A single object
Each object should have consistent keys that will be used as CSV headers.
Error Handling
The converter includes error handling for:
- Invalid JSON input
- Empty data
- File system errors
- Invalid arguments
