https://github.com/vincentmorneau/json-mapping
Change the structure of an existing JSON object with this mapping module
https://github.com/vincentmorneau/json-mapping
json key mapping property value
Last synced: 24 days ago
JSON representation
Change the structure of an existing JSON object with this mapping module
- Host: GitHub
- URL: https://github.com/vincentmorneau/json-mapping
- Owner: vincentmorneau
- License: mit
- Created: 2017-04-05T03:08:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:32:04.000Z (almost 3 years ago)
- Last Synced: 2025-04-15T15:04:31.229Z (6 months ago)
- Topics: json, key, mapping, property, value
- Language: JavaScript
- Homepage:
- Size: 990 KB
- Stars: 13
- Watchers: 1
- Forks: 5
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# JSON Mapping
[]() [](https://travis-ci.org/vincentmorneau/json-mapping) [](https://david-dm.org/vincentmorneau/json-mapping) [](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)