Warning: this repo is not maintained anymore. It will continue to exist as I am aware of projects which depend on it. If you need to make changes, please fork this repo
A gulp plugin for deep-merging multiple JSON files into one file. Any conflicting attributes are recorded and output to the console once the merge has completed.
The main use case, and the reason that this plugin was developed, is the merging of language files.
var merge = require('gulp-controlled-merge-json');
/*
Basic functionality
*/
gulp.src('jsonFiles/**/*.json')
.pipe(merge('combined.json'))
.pipe(gulp.dest('./dist'));
This will merge your input files into a file called "combined.json" and then output them into your dist directory.
This is an example of an input where there are no conflicting keys
/*
json/defaults.json
*/
{
"key1": {
"data1": "value1",
"data2": "value2"
},
"key2": {
"dataA": "valueA",
"dataB": {
"a": "b",
"c": "d"
}
}
}
/*
json/development.json
*/
{
"key1": {
"data1": "devValue"
},
"key2": {
"dataB": {
"c": "DEV MODE!"
}
},
"key3": {
"important": "value"
}
}
/*
dist/combined.json
*/
{
"key1": {
"data1": "devValue",
"data2": "value2"
},
"key2": {
"dataA": "valueA",
"dataB": {
"dataA": "valueA",
"dataB": {
"a": "b",
"c": "DEV MODE!"
}
}
},
"key3": {
"important": "value"
}
}
In the event of a conflict, the first value will be merged and the attribute name will be output to the console.
conflicting keys have been found
Key myKey found in /path/to/jsonFile.json but also in /path/to/other/jsonFile.json
The plugin will then emit an error.
Based on gulp-merge-json by @joshswan. Adapted by @robinj (Robin Janssens).