# Sending JSON data to a table

**URL:** https://discourse.nodered.org/t/sending-json-data-to-a-table/69627
**Category:** General
**Created:** [26 October 2022 13:20 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627 "2022-10-26T13:20:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [26 October 2022 13:20 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/1 "2022-10-26T13:20:23Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 October 2022 13:26 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/2 "2022-10-26T13:26:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [26 October 2022 14:04 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/3 "2022-10-26T14:04:05Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 October 2022 14:22 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/4 "2022-10-26T14:22:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [26 October 2022 14:29 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/5 "2022-10-26T14:29:24Z")

</div>

Thanks again for your reply E1cid.

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

Payload removed by OP..

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 October 2022 14:46 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/6 "2022-10-26T14:46:03Z")

</div>

I would [array.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) or [ForEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) through the result array and [push](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) a new object to the output array.  
Then set the output to msg.payload.  
e.g.

```auto
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.

---

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [26 October 2022 15:02 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/7 "2022-10-26T15:02:37Z")

</div>

Awesome! Works great.

Thank you very much!

---

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [4 November 2022 22:58 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/8 "2022-11-04T22:58:03Z")

</div>

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..

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

```

and

```auto
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.

---

<div class="post-metadata">

### Author: ![Timmer2022](https://avatars.discourse-cdn.com/v4/letter/t/df788c/32.png) [@Timmer2022](https://discourse.nodered.org/u/Timmer2022)
#### Post date: [4 November 2022 23:36 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/9 "2022-11-04T23:36:58Z")

</div>

I believe i got it..

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

```

seems to work..

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 January 2023 23:37 UTC](https://discourse.nodered.org/t/sending-json-data-to-a-table/69627/10 "2023-01-03T23:37:11Z")

</div>

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