Socket
Socket
Sign inDemoInstall

@compassdigital/mergejson

Package Overview
Dependencies
3
Maintainers
39
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @compassdigital/mergejson

Recursively merge json documents in a new one


Version published
Maintainers
39
Created

Readme

Source

Recursively merge json documents in a new one.

Node.js Usage

npm install @compassdigital/mergejson --save
var mergejson = require('@compassdigital/mergejson')

var dominant = {
    '1':'hello',
    '3':{
        '3.1': 'jhon',
        '3.2': 'doe'
    }
}
var recessive = {
    '2': 'world',
    '3':{
        '3.1': 'jhon',
        '3.2': 'lennon'
    }
}

console.log(mergejson(dominant, recessive));
// -> {'1': 'hello', '2': 'world', '3': {'3.1': 'jhon', '3.2': 'doe'}} 


var one = {
    '1':'hello',
    '4':{
        '4.1': 'jhon',
        '4.2': 'doe'
    }
}
var two = {
    '2': 'world',
    '4':{
        '4.1': 'jhon',
        '4.2': 'lennon',
        '4.3': 'from two'
    }
}

var three = {
    '3': '!',
    '4':{
        '4.1': 'jhon',
        '4.2': 'lennon',
        '4.3': 'from three'
    }
}

console.log(mergejson(one, two, three));
// -> {'1': 'hello', '2': 'world', '3': '!', '4': {'4.1': 'jhon', '4.2': 'doe', '4.3': 'from two'}} 

console.log(mergejson([one, two, three]));
// -> {'1': 'hello', '2': 'world', '3': '!', '4': {'4.1': 'jhon', '4.2': 'doe', '4.3': 'from two'}} 

Terminal Usage

npm install -g mergejson
mergejson {\"1\":\"one\"} {\"2\":\"two\"} {\"3\":\"three\"}
# ->
#
# {
#   '1': 'one',
#   '2': 'two',
#   '3': 'three'
# }

mergejson $(cat one.json) $(cat two.json) $(cat three.json)
# ->
#
# {
#   '1': 'one',
#   '2': 'two',
#   '3': 'three'
# }

Keywords

FAQs

Last updated on 02 Dec 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc