Remove empty string from json-input

I extract information from MySQL Database via MySQL Node. After this i want to remove empty/NULL Values from the JSON INPUT. I tried JavaScript or Filter-Node but i don’t get the expected result (i have no knowledge about javascript).

Here is the JS is used

// Angenommene Eingabe von $input.all()
const input = $input.all(); // Dies gibt das oben genannte Array zurück

// Funktion um null-Werte aus dem JSON zu entfernen
const removeNulls = (data) => {
  return data.map(item => {
    // Erstelle ein neues Objekt ohne die null-Werte
    return Object.fromEntries(
      Object.entries(item).filter(([_, value]) => value !== null)
    );
  });
};

// Anwendung der Funktion
const cleanedData = removeNulls(input);

// Ausgabe der bereinigten Daten
return cleanedData;

Share the output returned by the last node

IS
Bildschirmfoto 2024-10-01 um 22.18.08

SHOULD
Bildschirmfoto 2024-10-01 um 22.18.33

Information on your n8n setup

  • n8n version: 1.33.1
  • Database (default: SQLite): MariaDB (i guess)
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: MacOS

Welcome to the community @Wuddy !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.


What is the reason you want to remove the properties with no values? Perhaps you can safely ignore them?

Anyway, to have the property removed from an object you can use delete method as per How To Remove a Property from a JavaScript Object.