# array-to-json

> An awesome module that convert a data array in a json and viceverse

Latest version **1.0.2** (published 2019-01-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install array-to-json
pnpm add array-to-json
yarn add array-to-json
bun add array-to-json
```

## 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 | 1.0.2 |
| Published | 2019-01-17 |
| First published | 2019-01-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | amanda-hg |
| Maintainers | amanda-hg |
| Keywords | array, json, object, convert |

## Links

- npm: https://www.npmjs.com/package/array-to-json
- Repository: https://github.com/amanda-hg/array-to-json
- Homepage: https://github.com/amanda-hg/array-to-json#readme
- Issues: https://github.com/amanda-hg/array-to-json/issues
- npm.io page: https://npm.io/package/array-to-json

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

- 1.0.2 (latest) — 2019-01-17
- 1.0.1 — 2019-01-11
- 1.0.0 — 2019-01-11

## README

# array-to-json

This module convert an array into a json and viceverse.
```js
[1,2,3,4,5] => {
                    1: {},
                    2: {},
                    3: {},
                    4: {},
                    5: {}
                }
```
# Usage

Just require the module like any other npm module 
```js
const convert = require('array-to-json');
```

# Methods

This module has four methods:

- arrayToJson: return a json object from an array
- jsonToArray: returns an array from a json object
- jsonKeysToArray: returns an array with all keys of a json object
- jsonValuesToArray: returns an array with all values of a json object

# Example
## arrayToJson
Input:
```js
const convert = require('array-to-json');

let array = [1,2,3,4,5];
const json = convert.arrayToJson(array);
console.log(json);

```
Output:
```js
{
    1: {},
    2: {},
    3: {},
    4: {},
    5: {}
}
```
## jsonToArray
Input:
```js
const convert = require('array-to-json');

let data = {
            "code": 108007,
            "prov": "FAY",
            "hcode": "H100007",
            "enable": 0,
            "comment": "something comment"  
            }
const array = convert.jsonToArray(data);
console.log(array);

```

Output:
```js
[ { code: '108007' },
  { prov: 'FAY' },
  { hcode: 'H100007' },
  { enable: 0 },
  { comment: 'something comment' } ]
```
## jsonKeysToArray
Input:
```js
const convert = require('array-to-json');

let data = {
            "code": 108007,
            "prov": "FAY",
            "hcode": "H100007",
            "enable": 0,
            "comment": "something comment"  
            }
const array = convert.jsonKeysToArray(data);
console.log(array);
```

Output:
```js
[ 'code', 'prov', 'hcode', 'enable', 'comment' ]
```
## jsonValuesToArray
Input:
```js
const convert = require('array-to-json');

let data = {
            "code": 108007,
            "prov": "FAY",
            "hcode": "H100007",
            "enable": 0,
            "comment": "something comment"  
            }
const array = convert.jsonValuesToArray(data);
console.log(array);
```

Output:
```js
[ '108007', 'FAY', 'H100007', 0, 'something comment' ]
```

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