Last 4 numbers are being changed by BigInt method

Hey,

We’ve got a REST call that returns two id’s.
“id”: {
“id1”: 8682604121359729092,
“id2”: -4624766493329595303
},
These are quite big and so when my tests were failing I noticed that the last three digits were being changed to zeros (Example: 8682604121359729000 instead of 8682604121359729092).
After some searching and saw that the value needed to be converted to a BigInt so, at first I used console.log(BigInt(8682604121359729092)) but that returned 8682604121359728640. In this case, the last 4 digits have been changed again but it still isn’t correct. Another suggestion was to use BigInt.asIntN(64, 8682604121359729092) but postman throws the error…
TypeError: Cannot convert 8682604121359729000 to a BigInt. As you can see, the value in the error also has the replaced zeros.
Although the values look right in the Response Body, if I send the response to the console, those values also show zeros on the end.

Any help would be appreciated since I need these id’s to run other tests.

I found a solution that resolved the issue. I just stringified the results of the JSON and pulled out those values using regex—extra steps but the best solution I could find.

UPDATE: I found this code online that provides the “fix”. I hope they can fix the pm.response.json() in Postman so it doesn’t zero out the numbers > 56 bits.

let jsonStr = pm.response.text();

const regex = “(":)(-?[0-9.]+)”;

const matches = jsonStr.matchAll(regex);

for(const match of matches){

jsonStr = jsonStr.replace(match[0], “":"” + match[2] + “"”);

}

var jsonData = JSON.parse(jsonStr);

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.