Mapping data structures to visual representation

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.

Answer №1

One way to organize your information is by creating an array of objects. This allows you to easily loop through the values and populate your table.

const data = {"artists": [{"name": "Start", "value": "Ready"},{"name": "Date", "value": "2017-09-11"},{ "name": "Crew", "value": "artists Crew 1" }],"labor":[{"name": "Start", "value":"Ready"},{"name": "Date", "value": "2017-09-2"},{ "name": "Crew", "value": " labor Crew 2" }],accountant: [{"name": "Start", "value": "Ready"},{"name": "Date", "value": "2017-09-13"},{ "name": "Crew", "value": "account Crew 3" }],"somethingElse":[{"name": "Start", "value": "Ready"},{"name": "Date", "value": "2017-09-14"},{ "name": "Crew", "value": "somethingElse Crew 4"}],},
tableData =Object.entries(data).map(x => ({ Ready: x[1][0].value, Date: x[1][1].value, Crew: x[1][2].value }));
console.log(tableData);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loop within a promise results in undefined

Within my application, there is a function that returns a promise. Inside this function, I wait for an image in the DOM to become available and then extract that element to generate base64 data from it. getCodesOfOneMerchant(merchantDataEntry: MerchantData ...

Exploring the functionality of className using materialUI

Attempting to test whether my component has a specific class is proving challenging. This difficulty stems from the fact that the class is generated using MaterialUI. For instance, I am looking for a class named spinningIconCenter, but in reality, it appea ...

Filtering out banned terms in a PHP string

I am currently facing a challenge with my Javascript code that dynamically generates an XML string. Once this string is sent to a PHP file, I need to ensure that it does not contain any malicious words that could potentially lead to SQL injection attacks. ...

The JQuery click event triggers on the second click, skipping the first click

I've tried searching online for a solution to my problem, but I couldn't find one that works. I have some events set up in a JavaScript function (immediate function invocation). As a result, the click event is not functioning properly. It only tr ...

Ways to retrieve data from angular output

When I log the full data from an Angular client, it shows: object { type: "message", target: {_}, errorCode: undefiend, errorMessage: undefined, data: "{\"data\":[\"124",\"611\"]}", lastEventId: ""} My goal is to extract on ...

Troubleshooting: Issues with executing a PHP script from jQuery

I found the source code on this website: It's an amazing resource, but I'm facing an issue where my JavaScript doesn't seem to be executing the PHP script... When I set a breakpoint in Chrome's debugger before the penultimate line (}) ...

Calculating velocity and displacement with a specific acceleration in JavaScript: A step-by-step guide

I am faced with a challenge involving a JSON file containing acceleration values in m/s^2 along with timestamps. On the other hand, I have a ThreeJS mesh that needs to translate and rotate based on input values. My goal is to pass velocity and displacement ...

Tips for verifying if the Selection object includes two adjacent elements that are both either 'Div' or 'P' nodes

I'm struggling to figure out how to determine if a user's selection contains two or more sibling divs or paragraphs. I'm new to working with the DOM and could use some guidance on this issue. Has anyone encountered this situation before, or ...

What caused Firestore to be interpreted as an Array in my program instead of a Collection Reference?

After developing a simple app on Vue, I wanted to add functionality by connecting it to an online database. With limited backend knowledge, I decided to give Firebase a try for its simplicity and speed. The issue arises when I attempt to retrieve data fro ...

Update the parent element's class style within a targeted div media query

I am facing a challenge where I want the width of my .container element to be 100% when the screen size reaches 900px. The issue is that I have used .container on multiple pages and only wish to change its appearance within the #sub-top div. The terminolo ...

The Link tag in the Hero.jsx file of Next.js is malfunctioning and failing to redirect to the intended URL

Having a problem with the button in my Hero.jsx component, part of the Page.js implementation. The button uses a Link tag to redirect to the url.js page, but it's not working as expected and showing an Error 404 page instead. I'm new to Next.js s ...

I am facing difficulty creating a dropdown menu with nested options that only appear when the user hovers over the main selection

Here are the parent options I have and the code I have attempted to build. I would like to include sub-options such as phones, radios, speakers under the electronics parent option and many more. <select id="category" name="category" class="dropDown"& ...

Java servlet failing to send JSON data to jquery ajax request

Currently, I am in the process of building a web application using JSP with servlet. I have implemented JSP to fetch data from the servlet using jQuery AJAX, which returns data in JSON format. However, when I attempt to convert the servlet response data in ...

Transform nested arrangements into strings

In my dataset, I have multiple nested dictionaries and lists. My goal is to convert the list into a dictionary where each element of the dictionary does not contain any nested structures. data = [ [ u'abc', u'1.2.3.4', 52, ...

A new long polling AJAX request is triggered whenever there is a change in the parameter

function AjaxRequest(params, url) { if (params) { this.params = params; this.type = "GET"; this.url = url; // this.contentType = "multipart/form-data"; this.contentLength = params.length;; } } AjaxRequ ...

The issue of texpress-session failing to set a cookie in a React application arises when the app is deployed

I'm encountering an issue where I can't establish session cookies in the browser for my MERN stack application. Everything works fine when both the express server and the react front end are running locally, but the problem arises after deploying ...

Create a Vue component that utilizes the v-for directive to iterate through a list of items, passing data from a

Imagine having two arrays with a similar structure like this: const individuals = [{name: "Jane Doe", id: "0001"},{name: "John Doe", id:"0002"}, {name: "Sam Smith", id: "0003"}, {name: "Joe ...

Get the audio file to start downloading by clicking an HTML anchor link, without relying on the browser's

In my current project, I have an anchor link that directs to an MP3 file. My goal is to allow users to download this file by either right-clicking and selecting "Save Target As..." or by simply clicking on the link. However, I have encountered a problem w ...

Manipulate state in parent component from child component using onClick function with React hooks

Hello, I am facing a challenge trying to store data from a modal (child function) within the main (parent) function. Depending on which button is clicked, the modal loads specific HTML content (all buttons perform the same action). export default function ...

Is React the key to achieving dynamic server-side rendering?

I've noticed that most SSR tutorials for React use React.hydrate on components that either have all their data or don't require any props, like: React.hydrate(<Home />, document.getElementById('root')). The issue I am facing is t ...