Looking for a way to extract values from JSON and display them in a Tableau table format? Here's a simplified version of the JSON data:
{
"jobs": [
{"name": "Start", "value": "Ready"},
{"name": "Date", "value": "2017-09-11"},
{"name": "Crew", "value": "Crew 3"}]
}
The goal is to convert this JSON into a structured table within Tableau. Each "name" element will serve as a column header, while the corresponding "value" should populate the respective column.
The desired table layout is as follows:
| Start | Date | Crew |
| Ready | 2017-09-11 | Crew 3 |
To achieve this, a schema needs to be created in Tableau as shown below:
myConnector.getSchema = function (schemaCallback) {
var cols = [
{ id : "start", alias : "Start", dataType: tableau.dataTypeEnum.string },
{ id : "date", alias : "Date", dataType: tableau.dataTypeEnum.datetime },
{ id : "crew", alias : "Crew", dataType: tableau.dataTypeEnum.string }];
Next, a JavaScript function can be used to process the JSON data and generate the table:
var resp = response; // Sample API response data in JSON format
var tableData = [];
// Iterate over the JSON object to map values to appropriate columns
for (var i = 0, len = feat.length; i < len; i++) {
tableData.push(
{ "start": resp[1]['value'] },
{ "date": resp[2]['value'] },
{ "crew": resp[3]['value'] });
}
table.appendRows(tableData);
doneCallback();
});
}
However, there might be an issue with alignment when viewing the generated table in Tableau. If each value is appearing in a new row rather than all in one row, consider revising your looping mechanism.
Reach out if you need assistance on how to iterate through the JSON data effectively to ensure each value lands in the correct position within the table.