dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

Not able to parse the json file #56

Closed siddhsuper closed 9 years ago

siddhsuper commented 9 years ago

Not able to parse the json file [I am new to javascript]

This is my json file location = './jsons/rep_controller.json': { "apiVersion": "v12", "kind": "SController", "id": "siddhweb-controller", "labels": { "name": "siddhee" } }

function loadJSONData(next) {
  logger.info('loadJSONData');
  var getStream = function () {
    var jsonData = './jsons/rep_controller.json',
        stream = fs.createReadStream(jsonData, {encoding: 'utf8'}),
        parser = JSONStream.parse('*');
        return stream.pipe(parser);
    };

getStream().on('data', function(data) {
 logger.info('received: - ', data);
});
};

Getting the error undefined

dominictarr commented 9 years ago

for such a small file there is no advantage to streaming. Just read it and then parse the whole thing with JSON.parse(str)

siddhsuper commented 9 years ago

Actually the problem was in the JSON file, and not able to do

 JSON.parse(str)

That's why I thought JSONStream will work for me.

Anyways thanks a ton for your immediate reply :+1: