Data Parameterization : Iterating through all the test data

Hi Team,

My test data file “data.json” has 1000 unique records
How can I iterate and run through this 1000 records and pass to my API endpoint ?
I tried below code but it’s always picking only one element, rest all are not getting iterated

sample code

import http from 'k6/http';
import { SharedArray } from 'k6/data';
import { check, sleep } from 'k6';

const token_address = new SharedArray('some data name', function () {
  return JSON.parse(open('./data.json')).token_address;
  });

export default function () {
    const res =http.get(`https://baseurl/list?chain=bsc&token_address=${token_address}`);
 
	check(res, {
      'is status 200': (r) => r.status === 200,   
        
    });
  }

Thanks in advance

Hi @shailendrakumaromkar

Welcome to the community forum :wave:

I believe you can make use of the documentation on data parameterization, under the section retrieveing unique data.

You can retrieve a different token from the JSON file for each VU using vu.idInTest - 1 when reading the array.

I hope this helps.

Cheers!