I'm trying to understand why when I'm parsing a JSON response which contains HTML the JSON.parse
do not fail but ignore such data which I'm trying to fetch from this endpoint http://registry.npmjs.org/core-js
.
Here an example.
fetch('http://registry.npmjs.org/core-js').then(response =>
response.json()).then(data => console.log(data));
The property readme is empty, while if you load the endpoint in the browser, readme is completely populated as:
"readme": "# core-js\n\nModular standard library for JavaScript. Includes polyfills for [ECMAScript 5, 2015, 2016, 2017](https://github.com/zloirock/core-js#ecmascript): [promises](https://github.com/zloirock/core-js#ecmascript-promise), [symbols](https://github.com/zloirock/core-js#ecmascript-symbol), [collections](https://github.com/zloirock/core-js#ecmascript-collections), iterators, [typed ... n\n**It's a global version (first 2 examples), for more info see [`core-js` documentation](https://github.com/zloirock/core-js/blob/v3/README.md).**\n",
But after parse it with JSON.parse
it looks like this
As you see, readme is empty. Why??
Just FYI, I noticed the original issue using Node.js using
body = JSON.parse(body.toString('utf8'));
but then I noticed in the browser I have the same result, however, it just happen in some packages when readme has some sort of characters, encoding or whatever that seems to fails silently. eg: with jquery this works fine.
fetch('http://registry.npmjs.org/jquery').then(response =>
response.json()).then(data => console.log(data));
Perhaps someone has an idea what's happening here. I've tried many different ways to remove line breaks and so on, but always with the same result.