I'm a little bit into gulp and I'm looking for the right combination of tasks to read n amount of similarly formatted json files, pull out a specific array from each, combine them, and save as a new file. I've successfully used gulp-concat to combine files, and gulp-json-editor to change values on one file, but I'm having a hard time wrapping my head around how to string the processes together.
n number of json files formatted as follows:
{
"id": "groupofthings1",
"things": [
{ ... },
{ ... },
],
...
}
Desired single file output containing all "things":
[
{ ... },
{ ... },
{ ... },
{ ... },
...
]
Took me a bit of searching, but ended up finding jsoncombine
It loads all json files and runs them through a custom function as a hash of json objects. Each json object is saved under its original files name.
gulp.src("./groups/of/things/**/things.json")
.pipe(jsoncombine("all-things.json",function(data){
// do any work on data here
return new Buffer(JSON.stringify(data));
}))
.pipe(gulp.dest("./dest"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With