CSV Helper

With ResourceHelper you can load the contents of .csv or .tsv files stored in Resources as an object. To use ResourceHelper, proceed as follows:

Installation

Add the file ResourceHelper.groovy to the Resources in your solution and set the path to /script_lib

For more details on managing files in your solution, see Resource File Manager.

Usage

  1. Add your .csv or .tsv file to the resources and set the path to /script_lib
  2. Populate a variable using the following code (replace 'your_filename_here' with the name of your file):

Example for csv files:

def myResourceData = ResourceHelper.loadCSV("your_filename_here");

Example for tsv files:

def myResourceData = ResourceHelper.loadTSV("your_filename_here");

ResourceHelper assumes the first line contains the headers and those will be used as keys.

Example

If your csv/tsv looks like this:

Firstname Lastname
Buffy Summers
Omar Little
Ellen Ripley
Jack Sparrow

The resulting object will be:

[
    [Firstname:Buffy, Lastname:Summers], 
    [Firstname:Omar, Lastname:Little], 
    [Firstname:Ellen, Lastname:Ripley], 
    [Firstname:Jack, Lastname:Sparrow]
]

Was this page helpful?