I have a problem when during a performance test I get a response that contains items like
{"item":{"id":2733382000000000049}}
The k6 response.json()
parses it as :
{"item":{"id":2733382000000000000}}
So it replaces the last digits with 0s.
Also if I try to log the response.body()
I get:
ERRO[0001] TypeError: Value is not an object: {"item":{"id":2733382000000000049}}
The maximum integer that javascript can safely work with is much smaller:
> console.log(Number.MAX_SAFE_INTEGER)
9007199254740991
So any way to bypass this in k6 without changing the backend code?
2
Answers
Use
response.text()
instead, then you MAY be able to do somethingSince I have no clue about the rest of the JSON you actually get, this may well be a very naive solution.
Based on what you’ve shown, it would work.
One solution is:
Preprocessing your string from API to convert it into string before parsing.
Optionally, you could convert it back into number for your own purpose.
Here is the RegExp to convert all numbers in your string (proceeded with 🙂 into strings:
Regex explanation:
s* any number of spaces
-? one or zero ‘-‘ symbols (negative number support)
d+ one or more digits
(…) will be put in the $1 variable