How to extract serialNumbers from the response and store it in a file


Hello everyone, am new to k6 here.
I have a requirement to extract the serialNumbers from the below response and store it to a file. I dont want to output it to the console, as there will be many of them when I conduct the performance test.

Can someone please tell me of all the options availaible in k6 to store the serialNumbers in a file.

Response Data: {\"wagerId\":100003753651,\"pilot\":false,\"serialNumbers\":[\"32334676820000023552062550266601\"],\"wager\":{\"dbg\":[{\"addOn\":[{\"columns\":1,\"cost\":1.0,\"gameTyp

I figured out a way to save it in influxdb.

Hi @tenzin19!

If you really want to write to file, then you can do it with xk6-file extension.
You can try something like this:

import http from "k6/http";
import file from 'k6/x/file';

export default function () {
  let r = http.get("");
  file.appendString("output.txt", r.body.length+'\n');

You can run it with a custom k6 binary after building it with xk6

xk6 build --with

Or you can run it simply with after installing it.

k6x run script.js
1 Like

Thanyou @bandorko :grinning:

1 Like