1.1.5 • Published 5 years ago

json-mapping v1.1.5

Weekly downloads
42
License
MIT
Repository
github
Last release
5 years ago

JSON Mapping

npm Build Status Dependency Status XO code style

Transform a JSON object structure.

Install

npm install json-mapping

Usage

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

NameTypeDescription
jsonobjectThe initial JSON object to be mapped
mapping*arrayAn array containing the mapping options
*mapping
NameTypeDescription
oldKeystringThe old property name to be mapped
newKeystringThe new property name to be mapped
values**arrayAn array of mapped values for this property mapping
dependsOn**objectDetermines the value for the newKey based on a condition
**values
NameTypeDescription
oldValueanyThe old value of the property to be mapped
newValueanyThe new value of the property to be mapped
**dependsOn
NameTypeDescription
keystringThe key to look for
ifanyThe value to evaluate for the key
ifValueanyWhen key === if, this will be the value of the newKey
elseValueanyWhen key !== if, this will be the value of the newKey

Methods

NameTypeReturnDescription
mapfunctionobjectMaps a JSON object using mapping options

Changelog

See changelog.

License

MIT © Vincent Morneau