Reputation: 57
I have a folder with about 400 json files that a former teammate pulled from an api with curl. I need to compile all those json files into one big json file. I am using the grunt-json-bake grunt plugin to do it. Heres my Gruntfile
/* global grunt */
module.exports = function (grunt) {
grunt.initConfig({
json_bake: {
"en": {
options: {},
files: {
"dist/final.json": ["jsonFiles/**.json"]
}
}
}
})
grunt.loadNpmTasks('grunt-json-bake');
grunt.registerTask("default", ["json_bake"]);
}
Everytime I run this it only pulls the last json file into the dist/final.json, like it has not even looped through all the json files in the jsonFiles/ directory.
Upvotes: 1
Views: 244
Reputation: 2121
What json_bake
does is parse a starter file listing some "include" directives and applying them, it does not concatenate files bluntly. They have a thorough example at https://github.com/MathiasPaumgarten/grunt-json-bake#recursive-bake-including-files-and-folders
So if you want to have the value of each file referenced as an entry in a file
array property of your final.json
, you need to first create a base.json
in your root directory with:
{
"files": "{{jsonFiles}}"
}
Then in your gruntfile you reference this base file:
json_bake: {
"en": {
files: {
"dist/final.json": ["base.json"]
}
}
}
Upvotes: 2