Saturday 8 April 2017

Json Decode and Parse Error node.js

Hi i am trying to do this

const request = require('request');
const zlib = require('zlib');
const opts = {
    uri: 'http://data.githubarchive.org/2015-01-01-15.json.gz',
    encoding: null,
};

request.get(opts, function(error, response, body) {
    if (!error) {
        zlib.gunzip(body, function(err, decoded) {
            if (err) {
                console.log(err)
            } else {
                var json_string = decoded.toString('utf-8').replace(/(\r\n|\n|\r)/gm, " ").trim();
                var json = JSON.parse(json_string);
                console.log("SJON", typeof json)
            }
        });
    }
});

i am doing following steps

  1. fetching data from url
  2. unzip that using zlib.gunzip
  3. converting that decoded data to string
  4. replacing all newline and beak statements
  5. I am trying to parse that string which throws error

i am getting error while parsing data using JSON.parse. this is public dataset of github. i don't know where i am getting wrong can any one help.



via Rayees

No comments:

Post a Comment