Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-shaper

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-shaper - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

examples/example1.js

4

package.json
{
"name": "json-shaper",
"version": "1.0.0",
"version": "1.0.1",
"description": "Shape a flat array into a molded json shape with deep nesting",

@@ -8,3 +8,3 @@ "author": "Chris Kalmar <christian.kalmar@gmail.com>",

"scripts": {
"test": "mocha --compilers js:babel-register --require test/setup.js -R spec --check-leaks **/*.js",
"test": "mocha --compilers js:babel-register --require test/setup.js -R spec --check-leaks lib/*.js",
"lint": "eslint .",

@@ -11,0 +11,0 @@ "lint:fix": "eslint . --fix",

@@ -5,3 +5,4 @@ # json-shaper

[![Build Status](https://travis-ci.org/chriskalmar/json-shaper.svg?branch=master)](https://travis-ci.org/chriskalmar/json-shaper)
[![codecov](https://codecov.io/gh/chriskalmar/json-shaper/branch/master/graph/badge.svg)](https://codecov.io/gh/chriskalmar/json-shaper)
[![coverage](https://codecov.io/gh/chriskalmar/json-shaper/branch/master/graph/badge.svg)](https://codecov.io/gh/chriskalmar/json-shaper)
[![npm version](https://badge.fury.io/js/json-shaper.svg)](https://www.npmjs.com/package/json-shaper)

@@ -18,3 +19,107 @@ Shape a flat array into a molded json shape with deep nesting

## How to use
```js
// import shaper
import { shaper } from 'json-shaper';
// load data to be transformed
import input from './data/input.js'
// define a schema to shape by
const schema = {
id: 'id',
firstName: 'first_name',
lastName: 'last_name',
workplace: {
id: 'office_id',
name: 'office_company_name',
address: {
street: 'company_street',
postCode: 'company_postcode',
country: 'company_cty',
}
},
isActive: 'user_is_active'
}
// generate transformer function based on schema
const transformer = shaper(schema)
// transform data
const result = input.map(transformer)
// profit
console.log(JSON.stringify(result, null, 2));
```
#### If the input data looks like this:
```js
[
{
"id": 32,
"first_name": "John",
"last_name": "Flow",
"office_id": 12,
"office_company_name": "ACME Inc.",
"company_street": "Rocket Street 3",
"company_postcode": "11122",
"company_cty": "Space City",
"user_is_active": false
},
{
"id": 100,
"first_name": "Mike",
"last_name": "",
"office_id": 532,
"office_company_name": "",
"user_is_active": true
},
...
...
...
]
```
#### json-shaper will transform it into this:
```js
[
{
"id": 32,
"firstName": "John",
"lastName": "Flow",
"workplace": {
"id": 12,
"name": "ACME Inc.",
"address": {
"street": "Rocket Street 3",
"postCode": "11122",
"country": "Space City",
}
},
"isActive": false
},
{
"id": 100,
"firstName": "Mike",
"lastName": "",
"workplace": {
"id": 532,
"name": "",
"address": {}
},
"isActive": true
},
...
...
...
]
```
## Performance / Benchmarks
// TODO
## License

@@ -21,0 +126,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc