【问题标题】:exclude directory structure in output with grunt-concat-json使用 grunt-concat-json 在输出中排除目录结构
【发布时间】:2017-09-21 06:21:48
【问题描述】:

我的 JSON 文件位于以下路径,我想将它们组合成一个 JSON,其键等于文件名。

src/
  john/
    doe/
       one.json
       two.json
       three.json

如果我的 grunt-concat-json 是这样构造的:

   "concat-json": {
        "en": {
            src: "src/john/doe/*.json",
            dest: "output.json"
        }
    }

输出.json:

{
 "src": {
    "john": {
      "doe": {
         one: {...},
         two: {...}
      }
    }
  }
}

我希望我的 output.json 是

{
  one: {...},
  two: {...}
}

我如何实现这一目标? 谢谢。

【问题讨论】:

    标签: json gruntjs concat


    【解决方案1】:

    解决办法如下:

    改变grunt中的concat-json如下:

    "concat-json": {
            "en": {
                src: "**/*.json",
                cwd: "src/john/doe",
                dest: "output.json"
            }
        }
    

    这里的 output.json 将是:

    {
      one: {...},
      two: {...}
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-14
      • 2015-01-22
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      相关资源
      最近更新 更多