Remove empty keys/variables from data

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.