com

combijson

merge objects easily

Showing:

Popularity

Downloads/wk

2

GitHub Stars

4

Maintenance

Last Commit

2yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

combijson Build Status Greenkeeper badge

yarn add combijson # or:
npm install --save combijson

This module helps you with easy and fast merging of several objects and/or JSON strings:

const combijson = require('combijson');

const obj1 = {hello: 'world'};
const obj2 = {hello: 'there', node: 'rocks'};

combijson([obj1, obj2]); // {hello: 'world', node: 'rocks'}

const obj3 = '{"hello": "there"}';
const obj4 = {hello: 'world'};

combijson([obj3, obj4]); // {hello: 'there'}

const obj5 = {};
const obj6 = {hello: {there: true}};
const obj7 = {hello: {there: false}};

combijson([obj5, obj6, obj7]); // {hello: {there: true}}

combijson accepts one array as an argument which can hold several objects. The index of each object represents its priority: combijson will go over each object starting with the one at index 0, all values of the following objects will only be added to the resulting object, so values from 'superior' objects won't be overwritten.

For example, if you want to create a configuration based on a template and user data, you could do:

const config = combijson([userdata, template]);

In this case, all user data would be added to the final object, and template keys would only be added if they don't yet exist in the userdata object already.

You can also pass an empty object/no argument at all without causing errors. The result would be an empty object.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100