wrangle-csv
v1.0.9
Published
CSV to JSON converter, with option of traditional JSON object or JSON arrays for easier use with python backend using pandas f.ex
Downloads
7
Maintainers
Readme
wrangle-csv
CSV wrangler to transform CSV into JSON object optimized for display in webapps, or JSON object of arrays optimized for interaction with a python/pandas/scikit/tensorflow backend via HTTP requests.
Example imports:
Traditional JavaScript
const fs = require("fs");
const wrangle = require("wrangle-csv");
const csvFile = fs.readFile("c:/path/to/your/file.csv");
const jsonArray = wrangle.csvToJsonArr(csvFile);
const jsonObject = wrangle.csvToJsonObj(csvFile);
Typescript
import * as fs from "fs";
import { csvToJsonArr, csvToJsonObj } from "wrangle-csv";
const csvFile = fs.readFile("c:/path/to/your/file.csv");
const jsonArray = csvToJsonArr(csvFile);
const jsonObject = csvToJsonObj(csvFile);
Methods
Assumes the following structure: 1st row = headers 1st column = label/indexing
CSV to JSON structured as arrays
csvToJsonArr(file, sep, newLine)
- file: accepts string
- sep (separator): default
,
- newLine: default
/n
Returns a JSON object with each row arranged as an array
CSV to JSON object
csvToJsonObj(file, sep, newLine)
- file: accepts string
- sep (separator): default
,
- newLine: default
/n
Returns a JSON object
TODO
- Error handling
- Remove duplication and refactor