New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

json-mapping

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-mapping

Small module to map a JSON structure to a new structure

latest
Source
npmnpm
Version
1.1.5
Version published
Maintainers
1
Created
Source

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

Keywords

json

FAQs

Package last updated on 03 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts