Git Product home page Git Product logo

json-mapping's Introduction

JSON Mapping

npm Build Status Dependency Status XO code style Greenkeeper badge

Change the structure of an existing JSON object with this mapping module.

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

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.

License

MIT © Vincent Morneau

json-mapping's People

Contributors

vincentmorneau avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.