I'm pulling JSON data from Wikipedia. However, I can't get it to stringify neatly and I don't understand why.
Here's my code.
request({url:formQuery(query), encoding:"utf8"}, (err, res, body) => {
if (err) handleErr(err)
console.log(JSON.stringify(body, null, 3))
})
If I just use plain console.log(body), the JSON outputs like this:
{"continue":{"rvcontinue":"20160314150329|710029514","continue":"||"},"query":{"normalized":[{ ...
But if I use stringify (as above), it looks like this:
"{\"continue\":{\"rvcontinue\":\"20160314150329|710029514\",\"continue\":\"||\"},\"query\":{\"normalized\":[{ ...
Stringify is adding a quote to the beginning of the string and escaping subsequent ones.
Why is this happening? Any help would be welcome.
JSON.parse(...);JSON.stringifyconverts json to string...that's correct output