The Conversion/HTMLTabletoJSON extension extracts an HTML table from the current page using an XPath and converts the table data into a JSON object.
This is useful when a journey needs to capture table content from a page and reuse the extracted values for validation, comparison, or later journey steps.
Parameters:
-
Xpathrequired, a string containing the XPath used to locate the HTML table element in the current document;
Note: The XPath must point to the table element itself. The script reads the first table row as headers and treats all following rows as data rows.
NLP usage
Use the extension in a journey by calling Conversion/HTMLTabletoJSON with the execute command. Pass each value to the matching extension input using as inputName.
Note: The returned JSON uses each table header as a key. Each key contains an array of cell values from that column.
execute "Conversion/HTMLTabletoJSON" using "//table[@id='customers']" as Xpath returning $tableexecute "Conversion/HTMLTabletoJSON" using "//table[contains(@class,'customer-table')]" as Xpath returning $tableYou can also pass a stored variable into the extension input.
execute "Conversion/HTMLTabletoJSON" using "$tableXpath" as Xpath returning $tablestore value "//table[@id='customers']" in $tableXpath
execute "Conversion/HTMLTabletoJSON" using "$tableXpath" as Xpath returning $tableExample output for a table with Name and City columns:
{
"Name": [
"John Smith",
"Jane Doe"
],
"City": [
"London",
"New York"
]
}This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: The script depends on browser DOM XPath support and can only read tables available in the current document. It assumes the first tr contains the headers and all later tr elements contain data. It reads only td cells from data rows, so complex tables with nested tables, grouped headers, row spans, column spans, hidden rows, or non-standard header placement may not be represented accurately.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 25/05/2026
Resources:
This extension does not require any external resource.
// Note this extension is not a product feature of Virtuoso and is not officially supported
// Extensions use javascript which may or may not be compatible with systems under test (SUTs)
// We welcome you to use this extension or adapt it for your needs
const tableXpath = Xpath;
const tableXpathResult = document.evaluate(tableXpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
const table = tableXpathResult.singleNodeValue;
if (!table) {
console.error('Table not found');
return;
}
const headerRow = table.querySelector('tr');
if (!headerRow) {
console.error('Header row not found');
return;
}
const headers = Array.from(headerRow.querySelectorAll('th, td')).map(header => header.innerText.trim());
if (headers.length === 0) {
console.error('No headers found');
return;
}
const rows = Array.from(table.querySelectorAll('tr')).slice(1); // Adjust if header row is different
if (rows.length === 0) {
console.error('No data rows found');
return;
}
const jsonTable = headers.reduce((acc, header) => {
acc[header] = [];
return acc;
}, {});
rows.forEach(row => {
const cells = Array.from(row.querySelectorAll('td'));
headers.forEach((header, index) => {
const cellValue = cells[index] ? cells[index].innerText.trim() : '';
jsonTable[header].push(cellValue);
});
});
return jsonTable;
Comments
0 comments
Please sign in to leave a comment.