The fetchCsvAndConvertToJson extension downloads a CSV file from a URL and converts its rows into JSON objects that can be stored in a Virtuoso variable and used for later assertions.
This is useful when a journey needs to validate table data, compare application output with a CSV data source, or reuse a CSV file stored behind a reachable URL or file environment variable.
Parameters:
-
fileUrlrequired, a string URL for the CSV file to fetch. The URL must be reachable from the browser execution context and return CSV text; -
separatoroptional, a string delimiter used to split CSV columns. If this input is blank, the extension uses comma,as the default separator.
Note: The CSV must include a header row because $.csv.toObjects() uses the header names as keys in the returned JSON objects. For example, a header named name can be asserted later as $jsonData[0].name.
How to apply this to your journey
Use the extension in a journey by calling fetchCsvAndConvertToJson with the execute command. Pass each value to the matching extension input using as fileUrl and as separator.
Note: This extension is asynchronous. It calls done(json) after the CSV is fetched and parsed, or doneError(error) if the download or parsing step fails.
execute "fetchCsvAndConvertToJson" using "https://example.com/data.csv" as fileUrl, "," as separator returning $jsonData
assert $jsonData[0].name equals "John"execute "fetchCsvAndConvertToJson" using "https://example.com/data.csv" as fileUrl returning $jsonData
assert $jsonData[0].name equals "John"You can also store the URL and separator in variables first, then pass those variables into the extension.
store value "https://example.com/data.csv" in $fileUrl
store value "," in $separator
execute "fetchCsvAndConvertToJson" using $fileUrl as fileUrl, $separator as separator returning $jsonData
assert $jsonData[0].name equals "John"store value "https://example.com/data.csv" in $fileUrl
execute "fetchCsvAndConvertToJson" using $fileUrl as fileUrl returning $jsonDataExample output for a CSV file with headers name and city:
[
{{
"name": "John",
"city": "London"
}}
]This extension requires the following resources:
https://cdnjs.cloudflare.com/ajax/libs/axios/0.27.2/axios.min.jshttps://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.slim.min.jshttps://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.21/jquery.csv.min.js
The extension should be configured as:
- Run asynchronously: Yes
- Scope: Global
Limitation: This extension depends on the browser execution context, network access to fileUrl, the configured CDN resources, Axios, jQuery, and jquery-csv. The CSV URL must be reachable from the journey browser and allowed by the target server, browser security model, proxy, and content security policy; otherwise the Axios request can fail before parsing starts. The returned JSON is based on $.csv.toObjects(), so it expects a usable header row and uses the configured separator only; unusual encodings, malformed quoting, multiline edge cases, duplicate or blank headers, locale-specific delimiters, very large files, or CSV content that does not match the selected separator can produce unexpected keys, missing values, or parsing failures. The extension does not validate schema, trim or normalize values, convert numeric strings to numbers, handle authentication, retry failed requests, or impose its own timeout. Async extension scripts must complete within Virtuoso's documented 120-second maximum execution window. Cross-browser note: This extension runs in the browser or device selected for the journey execution. Because it uses browser networking plus external JavaScript libraries, behavior can differ from Virtuoso's default Chromium-based browser in Safari, Firefox, Edge, iOS, Android, or remote-grid executions, especially where network access, CORS handling, CDN loading, file URLs, proxy rules, or browser library compatibility differ. Validate it in each browser/device configuration used by your plan.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 30/04/2025
Resources:
https://cdnjs.cloudflare.com/ajax/libs/axios/0.27.2/axios.min.jshttps://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.slim.min.jshttps://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.21/jquery.csv.min.js
// Last updated: 30/04/2025, 13:49:14 UTC
// Resources:
// https://cdnjs.cloudflare.com/ajax/libs/axios/0.27.2/axios.min.js
// https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.slim.min.js
// https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.21/jquery.csv.min.js
async function fetchCsvAndConvertToJson(){
try {
const customSeparator = separator ? separator : ",";
const { data } = await axios.get(fileUrl)
const json = $.csv.toObjects(data, { separator: customSeparator })
done(json)
} catch(error) {
doneError(error)
}
}
fetchCsvAndConvertToJson()
Comments
0 comments
Please sign in to leave a comment.