Hi I'm 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'm following the below steps:
- fetching data from url
- unzip that using zlib.gunzip
- converting that decoded data to string
- replacing all newline and beak statements
- I'm trying to parse that string which throws error
I'm getting error while parsing data using JSON.parse, this is public dataset of github. I don't know where I'm going wrong, can any one help.
json_stringbefore decoding it? Is it a valid JSON?node-inspector) to examine the contents ofjson_stringbefore parsing. (Or in this case,console.logmay be sufficient; normally a debugger is better, you get much better insight into what's happening.)JSON.parsein Node isn't broken. Show the string.