0

I have to do a gulp task where am trying to read a json file(array of objects) and I want to write a single object into another file.

json:

    {
    "Files": [{
        "dev": {
            "POIBasePath": "poi",
            "basePathSearch": "search-v1",
            "contentType": "application/json",
            "timeOut": 10000
        }
    }, {
        "qa": {
            "POIBasePath": "poi",
            "basePathSearch": "search-v1",
            "contentType": "application/json",
            "timeOut": 10000
        }
    }]
}

Gulp task:

    gulp.task('readFile', function() {
    return gulp.src('app/dataConfig.json')
        .pipe(fs.readFile("app/dataConfig.json", "utf-8", function(err, data){
            console.log(data);//getting the total json object here
            fs.writeFile('app/scripts/apiConfig.js', data.Files[0].dev);
        }))
        .pipe(gulp.dest('./dest/'))
})

Here when i am trying to access data.Files[0].dev i am getting undefined

Any help would be appreciated

Shikha thakur
  • 1,269
  • 13
  • 34
  • Possible duplicate of [Using Node.JS, how do I read a JSON object into (server) memory?](http://stackoverflow.com/questions/10011011/using-node-js-how-do-i-read-a-json-object-into-server-memory) – Rene Nov 10 '16 at 09:55
  • Possible duplicate of [Read a bunch of JSON files, transform them, and save them](http://stackoverflow.com/questions/39209445/read-a-bunch-of-json-files-transform-them-and-save-them) – Sven Schoenung Nov 10 '16 at 10:07

0 Answers0