matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.96k stars 290 forks source link

If there are big numbers in response, how can we process them? #168

Closed djheart0710 closed 3 years ago

djheart0710 commented 6 years ago

In my project, I use fetch to process request. The result contains big numbers, which exceed the max number in JS. After response.json() , I got the data, but the big number data has already became wrong. For example, I got 14355897211814021 in Postman, but in project, I got 14355897211814020. How can I process the response got by fetch? Thanks!

mderijcke commented 5 years ago

This is how V8's JSON.parse works. You can use lossless-json for this though.

Use it like this:

const fetch = require('isomorphic-fetch');
const LosslessJSON = require('lossless-json');

setImmediate(async () => {
    let response = await fetch(/* ... */);

    let json = LosslessJSON.parse(await response.text());

    console.log(json);
});
jimmywarting commented 5 years ago

or perhaps use json-bigint?

matthew-andrews commented 3 years ago

Interesting problem ! Believe your question has been answered … …