# json-mapping

> Small module to map a JSON structure to a new structure

Latest version **1.1.5** (published 2020-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-mapping
pnpm add json-mapping
yarn add json-mapping
bun add json-mapping
```

## 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.1.5 |
| Published | 2020-08-03 |
| First published | 2017-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 24.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | vincentmorneau |
| Keywords | json, mapping |

## Links

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

## Dependencies (3)

- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [lodash.unset](https://npm.io/package/lodash.unset.md) ^4.5.2

## 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.1.5 (latest) — 2020-08-03
- 1.1.4 — 2019-02-04
- 1.1.3 — 2019-02-04
- 1.1.2 — 2018-04-20
- 1.1.1 — 2017-12-06
- 1.1.0 — 2017-05-05
- 1.0.1 — 2017-05-02
- 1.0.0 — 2017-04-05

## README

# JSON Mapping

[![npm](https://img.shields.io/npm/v/json-mapping.svg)]() [![Build Status](https://travis-ci.org/vincentmorneau/json-mapping.svg?branch=master)](https://travis-ci.org/vincentmorneau/json-mapping) [![Dependency Status](https://david-dm.org/vincentmorneau/json-mapping.svg)](https://david-dm.org/vincentmorneau/json-mapping) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

Transform a JSON object structure.

## Install
```
npm install json-mapping
```

## Usage
```javascript
const mapping = require('json-mapping');

let json = {
	"appURL": "localhost",
	"object1": {
		"bool": true,
		"name": "app"
	}
};

json = mapping.map(json, [
	{
	    oldKey: "appURL",
	    newKey: "url"
	},
	{
	    oldKey: "object1.bool",
	    newKey: "object1.enabled"
	}
]);
/*
{
	"url": "localhost",
	"object1": {
		"enabled": true,
		"name": "app"
	}
}
*/
```

## Arguments
Name | Type | Description
--- | --- | ---
json | object | The initial JSON object to be mapped
mapping* | array | An array containing the mapping options

###### \*mapping
Name | Type | Description
--- | --- | ---
oldKey | string | The old property name to be mapped
newKey | string | The new property name to be mapped
values** | array | An array of mapped values for this property mapping
dependsOn** | object | Determines the value for the newKey based on a condition

###### \*\*values
Name | Type | Description
--- | --- | ---
oldValue | any | The old value of the property to be mapped
newValue | any | The new value of the property to be mapped

###### \*\*dependsOn
Name | Type | Description
--- | --- | ---
key | string | The key to look for
if | any | The value to evaluate for the key
ifValue | any | When key === if, this will be the value of the newKey
elseValue | any | When key !== if, this will be the value of the newKey

## Methods
Name | Type | Return | Description
--- | --- | --- | ---
map | function | object | Maps a JSON object using mapping options

## Changelog
[See changelog.](changelog.md)

## License
MIT © [Vincent Morneau](http://vmorneau.me)

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