[英]Compiling multiple json files into one with grunt-json-bake
I have a folder with about 400 json files that a former teammate pulled from an api with curl. 我有一个文件夹,其中包含约400个json文件,该文件是前队友从带有curl的api中提取的。 I need to compile all those json files into one big json file. 我需要将所有这些json文件编译为一个大json文件。 I am using the grunt-json-bake grunt plugin to do it. 我正在使用grunt-json-bake grunt插件来做到这一点。 Heres my Gruntfile 这是我的Gruntfile
/* global grunt */
module.exports = function (grunt) { module.exports =函数(咕unt声){
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. 每次我运行此命令时,它只会将最后一个json文件拉到dist / final.json中,就像它甚至没有遍历jsonFiles /目录中的所有json文件一样。
What json_bake
does is parse a starter file listing some "include" directives and applying them, it does not concatenate files bluntly. json_bake
所做的是解析一个列出一些“ include”指令并应用它们的启动文件,它不会直截了当地连接文件。 They have a thorough example at https://github.com/MathiasPaumgarten/grunt-json-bake#recursive-bake-including-files-and-folders 他们在https://github.com/MathiasPaumgarten/grunt-json-bake#recursive-bake- includes-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: 因此,如果要在final.json
的file
数组属性final.json
每个文件的值引用为条目,则需要首先在根目录中使用以下命令创建一个base.json
:
{
"files": "{{jsonFiles}}"
}
Then in your gruntfile you reference this base file: 然后在您的gruntfile中引用此基本文件:
json_bake: {
"en": {
files: {
"dist/final.json": ["base.json"]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.