Parsing CSV data in K6 script

Hello All,
I have a simple K6 js script that reads through a CSV file and tries to identify the individual values. When i try to extract the values it renders unidentified for username while it is able to recognize password, What am i doing wrong here?
CSV file data:

username,password
kiru,kiru123
vasu,vasu123

Code snippet:

export default function() {
// Get the current iteration index
const index = __ITER % csvData.length;

// Get the data for the current iteration
const data = csvData[index];

// Log the data to the console
console.log('Data for current iteration:', JSON.stringify(data));

 
    console.log('username:' , `${data.username}`);
    console.log('password:' , `${data.password}`);

Output:
INFO[0000] Data for current iteration: {“username”:“kiru”,“password”:“kiru123”} source=console
INFO[0000] username: undefined source=console
INFO[0000] password: kiru123 source=console

This is quite peculiar, and it suggests that there might be something unusual about the “username” string itself.
You probably already tried this, but to pinpoint the issue:

  1. Inspect the raw CSV data:
  • Open your users.csv file in a plain text editor (like Notepad, Sublime Text, or VS Code).
  • Carefully examine the “username” values. Look for:
    • Invisible characters: There might be non-printable Unicode characters before, after, or within the “username” strings that are interfering with how K6 interprets them.
    • Encoding issues: Ensure your CSV file is saved with UTF-8 encoding.
1 Like

I tried all of the above but could not fix it, but I deleted the file and recreated a new one and that seems to have resolved it. Thanks @grant2 for taking the time to explain. Appreciate your help.