Remove empty keys/variables from data

What are you trying to achieve?

I have data coming in with multiple field values:

Key A has data
Key B empty
Key C empty
Key D empty
Key E empty
Key F empty

I already have this added to an array as well, but whatever i try, i can’t remove the empty ones, the main problem being they all have a different name, so filtering doesn’t work to my knowledge, how can i remove them without needing 10 modules?
(if there is data or not for these keys is different for every cycle, so the solution needs to be flixible enough to work with every scenario)

Also, A, B, C etc needs to stay in tact, I need that later on.

Steps taken so far

Tried filters with different structures, tried mapping the array, tried searching existing topics here, tried using AI, tried using chatGPT, I am working at this for 4 hourds now, so, i’ve tried a lot of things, none of them do what i need.

1 Like

Hey there,

can you share the array it self for easier checking?

1 Like

it is:

  • Array
    • 1 Collection
      • Key A Data
      • Key B empty
      • Key C empty
      • Key D empty
      • Key E empty
      • Key F empty

And i need to just remove every “Key ..” that is empty, without changing the names.

Sorry, as in - copy paste it from your scenario so we can test with it. Ideally just copy the entire bundle here.

for privacy reasons of the data i’m working with, i cannot uload anything, this was a copy-paste from the module.

Sorry but without specific data, we cannot offer a specific solution.

In general, what you need to do is iterate the array, put a filter that only allows items with values inside and then aggregate the array back.

So, everybody that has a question shares sensitive data? I would get in big trouble if i did that.

I litterally copy/pasted the data, it doesn’t get much more specific than this.

is exactly:

  • Array
    • 1 Collection
      • Key A Data
      • Key B Data
      • Key C Data
      • Key D empty
      • Key E empty
      • Key F empty

Welcome to the Make community!

You can try running some JavaScript code to go through each property in the collection (object), and remove that property if it is null.

Here is an example using a free module that can run JavaScript code, which you can get from this post: Is there a way to count tokens? - #3 by samliew

Output:

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":212,"module":"json:ParseJSON","version":1,"parameters":{"type":""},"mapper":{"json":"{\"array\":[{\n\"A\": \"value1\",\n\"B\": \"value2\",\n\"C\": \"value3\",\n\"D\": null,\n\"E\": null,\n\"F\": null\n}]}"},"metadata":{"designer":{"x":1521,"y":-554,"name":"Set Demo Variable"},"parameters":[{"name":"type","type":"udt","label":"Data structure"}]}},{"id":215,"module":"app#sams-toolbox-mls54z:basicjs","version":1,"parameters":{},"mapper":{"code":"function removeEmptyProps(collection) {\n  Object.keys(collection).forEach(k => {\n    if (!collection[k]) delete collection[k];\n  });\n  return collection;\n}\nremoveEmptyProps(input.myCollection);","input":[{"key":"myCollection","value":"{{first(212.array)}}"}]},"metadata":{"designer":{"x":1764,"y":-554}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

I figured out how to do it with just these five built-in functions: slice distinct add toArray first

e.g.: (paste this into the field)

{{slice(distinct(add(toArray(first(1.array)); null); "value"); 0; -1)}}

Screenshot_2025-03-29_230341

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

2 Likes

You are a genius, both options do exactly what I need, thank you so much!

1 Like