# Data Formatting

**URL:** https://discourse.nodered.org/t/data-formatting/56636
**Category:** Dashboard
**Created:** [14 January 2022 04:55 UTC](https://discourse.nodered.org/t/data-formatting/56636 "2022-01-14T04:55:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mjrtoo](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Mjrtoo](https://discourse.nodered.org/u/Mjrtoo)
#### Post date: [14 January 2022 04:55 UTC](https://discourse.nodered.org/t/data-formatting/56636/1 "2022-01-14T04:55:20Z")

</div>

Node Red noob,

I am doing an HTTP request and successfully getting that data back fine, I am using JSONata to create an array from that data for use on the dashboard as a table, all that is working fine...I see all the data appropriately on the dashboard. However, I would like to remove array key:value pairs I don't need from the array so the dashboard only displays the desired data. I've tried using a change on the msg.payload to an expression of

`$ ~> |$|{}, ['Id', 'IntegrationProjectId', 'ClientId', 'ClientNumber', 'Approved', 'CONumber', 'CurrencyCode', 'Price', 'ImportedOn', 'PublishedOn', 'Deleted']|`

and it works in the test of the change when I paste in the array but not in deploy, it turns it back into an object instead of an array with the expression applied.

If anyone can help me out I would appreciate it. I don't want to include the flow because it contains an API key I can't share.

EDIT, here's a flow with an inject with the data I need to remove the fields from for display in the table, the fields I need to remove are above in the expression.

```auto
[{"id":"2d4745ba43201053","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"83c837deb0b211cb","type":"ui_table","z":"2d4745ba43201053","group":"a2a36cb0373d7204","name":"Table","order":5,"width":"0","height":"0","columns":[],"outputs":0,"cts":false,"x":930,"y":140,"wires":[]},{"id":"784789570e33411a","type":"inject","z":"2d4745ba43201053","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Id\":\"xxx\",\"IntegrationProjectId\":null,\"ClientId\":\"xxx\",\"Client\":\"Dermatology\",\"ClientNumber\":null,\"Name\":\"Waiting Room Monitors\",\"Number\":\"D6\",\"Progress\":\"02 - Estimation (Engineer)\",\"Approved\":false,\"CONumber\":null,\"CurrencyCode\":\"USD\",\"Price\":0,\"ImportedOn\":null,\"PublishedOn\":\"2022-01-13T20:42:00\",\"Deleted\":null},{\"Id\":\"yyy\",\"IntegrationProjectId\":null,\"ClientId\":\"yyy\",\"Client\":\"Northy\",\"ClientNumber\":null,\"Name\":\"AJA 104K Plus\",\"Number\":\"DT5\",\"Progress\":\"02 - Estimation (Engineer)\",\"Approved\":false,\"CONumber\":null,\"CurrencyCode\":\"USD\",\"Price\":0,\"ImportedOn\":null,\"PublishedOn\":\"2022-01-12T22:41:00\",\"Deleted\":null}]","payloadType":"json","x":530,"y":140,"wires":[["83c837deb0b211cb"]]},{"id":"a2a36cb0373d7204","type":"ui_group","name":"Project Information","tab":"f449e75060c583f8","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f449e75060c583f8","type":"ui_tab","name":"D-Tools Project Data","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [14 January 2022 05:52 UTC](https://discourse.nodered.org/t/data-formatting/56636/2 "2022-01-14T05:52:22Z")

</div>

Try with function like this

```auto
// declare set of keys you don't need
const redundant = new Set(['Id', 'Client', 'Progress']);

for (let obj of msg.payload) {
    for (let prop of Object.keys(obj)) {
        if (redundant.has(prop)) {
            delete obj[prop];
        }
    }
}
return msg;

```

---

<div class="post-metadata">

### Author: ![Mjrtoo](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Mjrtoo](https://discourse.nodered.org/u/Mjrtoo)
#### Post date: [14 January 2022 06:06 UTC](https://discourse.nodered.org/t/data-formatting/56636/3 "2022-01-14T06:06:03Z")

</div>

Thanks, I'll give it a try in the morning!

I was just doing a little looking and came up with this, think this might also work?

```auto
Obj = msg.payload;

for (var i = 0; i < obj.length; i++) {
    delete obj[i].Id
    delete obj[I].çlientId
}
return msg;

```

I'm not even sure if you can assign a variable the payload like that...

---

<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: [14 January 2022 08:00 UTC](https://discourse.nodered.org/t/data-formatting/56636/4 "2022-01-14T08:00:54Z")

</div>

The issue is you did not enter the data in the test window as payload.  
this should work

```auto
$$.payload ~> |$|{}, ['Id', 'IntegrationProjectId', 'ClientId', 'ClientNumber', 'Approved', 'CONumber', 'CurrencyCode', 'Price', 'ImportedOn', 'PublishedOn', 'Deleted']|

```

or

```auto
$$.payload ~> |$|$, ['Id', 'IntegrationProjectId', 'ClientId', 'ClientNumber', 'Approved', 'CONumber', 'CurrencyCode', 'Price', 'ImportedOn', 'PublishedOn', 'Deleted']|

```

But I would go with this as it gives you the opportunity to change the property names to and is cleaner(IMO).

```auto
$$.payload.{
   "Client":$.Client,
   "Name":$.Name,
   "Number":$.Number,
   "Progress":$.Progress
}

```

---

<div class="post-metadata">

### Author: ![Mjrtoo](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Mjrtoo](https://discourse.nodered.org/u/Mjrtoo)
#### Post date: [14 January 2022 14:25 UTC](https://discourse.nodered.org/t/data-formatting/56636/5 "2022-01-14T14:25:02Z")

</div>

I used your 'include' rather than 'delete' method and it worked perfectly, thank you, I appreciate the help!

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [14 January 2022 14:58 UTC](https://discourse.nodered.org/t/data-formatting/56636/6 "2022-01-14T14:58:09Z")

</div>

I would always chose a function node over JSONata (for speed and maintainability)

The below is an example using [`Array.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) - it returns the fields of interest...

```auto
msg.payload = msg.payload.map(e => {
    return {
        Id: e.Id,
        ClientId: e.ClientId,
        Progress: e.Progress
    }
})
return msg;

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e64006eae0b17a49830a1d48c8058ee9e9b6c1d1.png)

---

<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: [28 January 2022 14:59 UTC](https://discourse.nodered.org/t/data-formatting/56636/7 "2022-01-28T14:59:00Z")

</div>

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