Data Formatting

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.

[{"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}]

Try with function like this

// 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;

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?

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

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

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

or

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

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

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

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

The below is an example using Array.map() - it returns the fields of interest...

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

image