https://github.com/ansteh/shape-array
convert array to json object
https://github.com/ansteh/shape-array
json shape-array
Last synced: 12 months ago
JSON representation
convert array to json object
- Host: GitHub
- URL: https://github.com/ansteh/shape-array
- Owner: ansteh
- License: mit
- Created: 2016-03-05T22:47:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-05T20:36:10.000Z (over 9 years ago)
- Last Synced: 2025-07-05T05:04:58.915Z (12 months ago)
- Topics: json, shape-array
- Language: JavaScript
- Size: 58.6 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ansteh/shape-array)
## Install
Using npm:
```js
npm install shape-array
```
## Usage
Shape array to a json object:
```js
'use strict';
const shape = require('shape-array');
const personify = shape.scheme(['id', 'name', 'address.street', 'address.zip']);
let data = [1, 'John', 'github', '1234'];
let person = personify(data);
//person equals:
{
id: 1,
name: 'John',
address: {
street: 'github',
zip: '1234'
}
}
```
Reverse json to array:
```js
const reverse = shape.reverse(['id', 'name', 'address.street', 'address.zip']);
let json = {
id: 1,
name: 'John',
address: {
street: 'github',
zip: '1234'
}
};
let array = reverse(json);
//array equals:
[1, 'John', 'github', '1234']
```
## Related
- [shape-json](https://github.com/ansteh/shape-json) - Convert json to json with a predefined scheme
- [difference-json](https://github.com/ansteh/difference-json) - Prompt the diffrence of two json objects
## License
MIT © [Andre Stehle](https://github.com/ansteh)