Sending JSON data to a table

Hello folks.

I am just starting out with Node-Red and need some help.. here is what I have so far:

  1. A timestamp inject connected to an http in node which gets a URL API from my baserow site. (the "Return" dropdown is set to "a parsed JSON object".
  2. Connected to the http in node is a debug showing the results..

The above works fine, I see the JSON data come in.

Now I'd like to send the results to a table and here is where I struggle..

I've tried adding a function node to my http in and then to a table.. In that function node, I tried a "for" loop to add the items in the table in turn but no matter what I've tried thus far, only 1 value shows up in the table..

Here is the code I've tried:

for (let index = 0; index < msg.payload.count; index++) {
    
msg.payload = [
    {
        "Name":msg.payload.results[index].Customer
        }
]
    node.send(msg);
}

In the above, I basically want one column, Name, with the customer populating in the table.. there should be 32 entries but I only ever get the first entry in the table.. I assumed the "for" loop would go through the JSON objects in turn with the index counter and spit the results out to the table..

Any assitance would be greatly appreciated..

Thanks in advance.
Tim.

A few things
I think you mean a http request node not an in node.
There is no count property of an array, i think you mean length.
What does your incoming payload look like.
You are overwriting the payload you are iterating through.
When you say table what exactly do you mean.

Hey E1cid.

Thanks for your reply.. Yes as I'm learning node-red, I'm bound to get some terminology incorrect..

The incoming payload looks like the following.. this is only part of it.. there's 32 entries of this stuff..

1: object
id: 4
order: "4.00000000000000000000"
Customer: "Camis"
Description: "Supply & install cellular amplifier system at Sibbald PPK; Park store location."
Technician: array[1]
Status: array[1]
Date added: "2022-08-18"
Service Order: "WO-016019"
Invoiced: true
Job Name: "Cell amplifier at Sibbald PPK."

So essentially I want to grab the customer from each entry and have in a dashboard table..

Table would look like:

Customer

CAMIS
CUSTOMER 2
CUSTOMER 3
CUSTOMER 4
...and so on so forth until count ends..

I'm using an index variable as the number of entries (currently 32) could vary..
If I'm overwriting the payload I'm iterating through, how do I avoid this? Have the iteration save to a variable array, then put it to table?

Again table has so many meanings, Html( page or ui-template), ui-table, tabulator, and many other dashboard, or you may mean a csv or excel.

The payload does not look like that, it is formatted. To copy it correctly use the debug side panel, if you hover the mouse to right of property name (payload) some icons will appear, one of them is copy value. These icon are very useful including copy path.

Thanks again for your reply E1cid.

So it is a ui-table I am trying to populate.

Payload removed by OP..

I would array.map() or ForEach() through the result array and push a new object to the output array.
Then set the output to msg.payload.
e.g.

let output  = [];
msg.payload.results.forEach(obj => {
    output.push({name: obj.Customer})
})
msg.payload = output
return msg;

The payload should just then be feed into the ui-table node.

1 Like

Awesome! Works great.

Thank you very much!

Hey E1cid.

What if I have an item in the payload that has a space in it?

For instance "Job Name" is one of the items..

I've tried the following to no avail..

output.push({jobname: obj.Job Name})

and

output.push({jobname: obj.["Job Name"]})

None of these work.. any ideas?

When I click on the icon to copy the path, I get payload.results[1]["Job Name"]

I appreciate any assistance you can provide.

Thanks.

I believe i got it..

["Job Name"]: obj["Job Name"],

seems to work..

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.