javascriptjsonk6

Getting k6 response with JSON object that contain long integer


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?


Solution

  • Use response.text() instead, then you MAY be able to do something

    // text would be the result of response.text()
    const text = '{"item":{"id":2733382000000000049}}'
    const fix = text.replace(/(\d{15,})/g, '"$1"');
    console.log(JSON.parse(fix))

    Since 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.