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
eId\":0,\"discount\":0}],\"blockStatus\":\"Unblocked\",\"boards\":[{\"boardId\":1,\"panels\":[{\"requested\":1,\"selection\":[337533]}]}],\"columns\":1,\"cost\":1.0,\"creationTime\":1700753804521,\"updatedTime\":1700753804521,\"disc
ount\":0.0,\"gameId\":21001}}

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("https://google.com");
  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 github.com/avitalique/xk6-file@latest

Or you can run it simply with https://github.com/szkiba/k6x after installing it.

k6x run script.js
1 Like

Thanyou @bandorko :grinning:

1 Like