Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khezen/mergejson
Recursively merge json documents in a new one
https://github.com/khezen/mergejson
client json npm
Last synced: 10 days ago
JSON representation
Recursively merge json documents in a new one
- Host: GitHub
- URL: https://github.com/khezen/mergejson
- Owner: khezen
- License: mit
- Created: 2016-10-23T17:22:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T13:51:17.000Z (over 3 years ago)
- Last Synced: 2024-10-14T03:07:17.083Z (about 1 month ago)
- Topics: client, json, npm
- Language: JavaScript
- Homepage:
- Size: 58.6 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM Version](http://img.shields.io/npm/v/mergejson.svg?style=flat)](https://www.npmjs.org/package/mergejson)
Recursively merge json documents in a new one.
# Node.js Usage
```
npm install mergejson --save
``````javascript
var mergejson = require('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'
# }
```