Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to parse CSV into array of objects keyed by the field name #4284

Open
going-confetti opened this issue Jan 27, 2025 · 2 comments
Open
Assignees
Labels

Comments

@going-confetti
Copy link

Feature Description

Background

We are adding support for data files to k6 Studio (grafana/k6-studio#363) and we would like to discuss a feature request.

In short, the user will be able to import a data file (CSV/JSON array) and use values from this file in Parameterization rules (e.g. Pick random row from users.csv and replace id in the request with the value of user_id from that row). From the UX perspective, the file type won't matter much and the UI of the parameterization rule editor will look something like this:

Image

What will be different is the actual file parsing code in the generated script. For CSVs, we plan on using k6/experimental/csv in the actual generated script, but the current return format of the parse function (array of string arrays) makes extraction of the specified value harder and means that we probably need different snippets for JSON and CSV.

What we're asking

Ideally, we'd like an option similar to header: true in papaparse:

id,name
1,hdb
const csvRecordsArr = await csv.parse(file, { delimiter: ',' }) // [['id', 'name'], ['1', 'hdb']]
const csvRecordsObj = await csv.parse(file, {delimiter: ',', header: true}) // [{ id: '1', name: 'hdb' }]

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

grafana/k6-studio#363

@going-confetti
Copy link
Author

@oleiade we had a brief discussion about this the other day

@oleiade
Copy link
Member

oleiade commented Jan 27, 2025

Thanks for opening this @going-confetti 🙇🏻

@oleiade oleiade removed the triage label Jan 27, 2025
@going-confetti going-confetti changed the title Option to parsing CSV into array of objects keyed by the field name Option to parse CSV into array of objects keyed by the field name Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants