# json-and-xlsx

> A package that converts JSON to XLSX and XLSX to JSON

Latest version **2.1.2** (published 2021-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-and-xlsx
pnpm add json-and-xlsx
yarn add json-and-xlsx
bun add json-and-xlsx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2021-01-27 |
| First published | 2020-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kusi Musah Hussein |
| Maintainers | mkhstar |
| Keywords | JSON, xlsx, excel, spreadsheet |

## Links

- npm: https://www.npmjs.com/package/json-and-xlsx
- Repository: https://github.com/mkhstar/json-and-xlsx
- Homepage: https://github.com/mkhstar/json-and-xlsx#readme
- Issues: https://github.com/mkhstar/json-and-xlsx/issues
- npm.io page: https://npm.io/package/json-and-xlsx

## Dependencies (3)

- [xlsx](https://npm.io/package/xlsx.md) ^0.15.5
- [dot-object](https://npm.io/package/dot-object.md) ^2.1.2
- [buffer-from](https://npm.io/package/buffer-from.md) 1.1.1

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

- 2.1.2 (latest) — 2021-01-27
- 2.2.0 — 2020-02-25
- 2.1.1 — 2020-02-17
- 2.1.0 — 2020-02-14
- 2.0.0 — 2020-02-13
- 1.0.2 — 2020-02-12
- 1.0.1 — 2020-02-12
- 1.0.0 — 2020-02-12

## README

# json-and-xlsx
A package for converting JSON to XLSX and XLSX to JSON

# Global Functions
| Param | Description |
| --- | --- |
| xlsxToJson | The function for handling xlsx to json conversion |
| jsonToXlsx | The function for handling json to xlsx conversion |

# xlsxToJson
This function is used to handle xlsx to json conversions

## readAndGet(xlsxData)
Reads workbook returns a json output

| Param | Type | Description |
| --- | --- | --- |
| xlsxData | workbook| The workbook to get in js |

## Usage
#### Xlsx Data in Sheet1

| title | description |
| --- | --- |
| Title 1 | Desc 1 |
| Title 2 | Desc 2 |

```javascript
const {xlsxToJson} = require('json-and-xlsx');

const workbook = require('./workbook'); // Get Workbook

const output = xlsxToJson.readAndGet(workbook);
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/
```

## readFromBufferAndGet(buffer)
Reads from a buffer and returns a json output

| Param | Type | Description |
| --- | --- | --- |
| buffer | Buffer | The buffer to get in js object |

## Usage
```javascript
const {xlsxToJson} = require('json-and-xlsx');
const buffer = require('./buffer-data.js');

const output = xlsxToJson.readFromBufferAndGet(buffer);
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/
```


## readFromFileAndGet(xlsxData)
Reads workbook returns a json output

| Param | Type | Description |
| --- | --- | --- |
| xlsxData | workbook| The workbook to get in js |

## Usage
#### Xlsx Data in Sheet1 stored in workbook.xlsx

| title | description |
| --- | --- |
| Title 1 | Desc 1 |
| Title 2 | Desc 2 |

```javascript
const {xlsxToJson} = require('json-and-xlsx');

const output = xlsxToJson.readFromFileAndGet('workbook.xlsx');
/*
    returns [
    {
        title: 'Title 1',
        description: 'Desc 1'
    },
    {
        title: 'Title 2',
        description: 'Desc 2'
    }
];
*/
```

# jsonToXlsx
This function is used to handle json to xlsx conversions

```json
//  json-data.json
[
    {
        "title": "Title 1",
        "description": "Desc 1"
    },
    {
        "title": "Title 2",
        "description": "Desc 2"
    }
]
```

## readAndGet(jsonData)
Reads json returns a workbook

```javascript
const {jsonToXlsx} = require('json-and-xlsx');

const jsonData = [
    {
        title: "Title 1",
        description: "Desc 1"
    },
    {
        title: "Title 2",
        description: "Desc 2"
    }
]; // Could be a JSON String

const output = jsonToXlsx.readAndGet(jsonData);
/*
    returns Workbook
*/
```


## readAndGetBuffer(jsonData)
Reads json returns a buffer of the workbook

```javascript
const {jsonToXlsx} = require('json-and-xlsx');

const jsonData = [
    {
        title: "Title 1",
        description: "Desc 1"
    },
    {
        title: "Title 2",
        description: "Desc 2"
    }
]; // Could be a JSON String

const output = jsonToXlsx.readAndGetBuffer(jsonData);
/*
    returns Buffer
*/
```


## readFromFileAndGet(sourceFilePath)
Reads json returns a workbook

```javascript
const {jsonToXlsx} = require('json-and-xlsx');

const output = jsonToXlsx.readFromFileAndGet('json-data.json');
/*
    returns Workbook
*/
```


## readFromFileAndGetBuffer(sourceFilePath)
Reads json from `sourceFile` and returns a Buffer

```javascript
const {jsonToXlsx} = require('json-and-xlsx');

const output = jsonToXlsx.readFromFileAndGetBuffer('json-data.json');
/*
    returns Buffer
*/
```


## readFromFileToFile(sourceFilePath, destFilePath)
Reads json from file and writes the workbook to a file

```javascript
const {jsonToXlsx} = require('json-and-xlsx');

jsonToXlsx.readFromFileToFile('json-data.json', 'workbook.xlsx');
/*
    writes json to workbook.xlsx
*/
```

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