Skip to main content
August 26, 2025
Question

How to remove keys from the list of map that has null values

  • August 26, 2025
  • 3 replies
  • 0 views

Hi, 

I want to remove the null value keys from the list of the map below. Please let me know how to achieve that:

{a!map(ABC: 6.7, EFG: 15.44, HIJ: 470.888, KLM: "9.8989984", OPQ: null), a!map(ABC: 8.4, EFG: 15.43, HIJ: 470.656, KLM: "9.2342", OPQ: null), a!map(ABC: 7.2, EFG: 15.42, HIJ: 470.554, KLM: "9.234234", OPQ: null), a!map(ABC: 5.6, EFG: 15.42, HIJ: 470.234, KLM: "9.63242", OPQ: null), a!map(ABC: "", EFG: 15.42, HIJ: 470.665, KLM: "9.54343", OPQ: null)}

Regards,

Sowvik

3 replies

shubhama926776
August 26, 2025

I have tried to replicate your requirement; please have a look at it.

a!localVariables(
  local!originalList: {
    a!map(ABC: 6.7, EFG: 15.44, HIJ: 470.888, KLM: "9.8989984", OPQ: null),
    a!map(ABC: 8.4, EFG: 15.43, HIJ: 470.656, KLM: "9.2342", OPQ: null),
    a!map(ABC: 7.2, EFG: 15.42, HIJ: 470.554, KLM: "9.234234", OPQ: null),
    a!map(ABC: 5.6, EFG: 15.42, HIJ: 470.234, KLM: "9.63242", OPQ: null),
    a!map(ABC: "", EFG: 15.42, HIJ: 470.665, KLM: "9.54343", OPQ: null)
  },

  a!forEach(
    items: local!originalList,
    expression: a!localVariables(
      local!currentMap: fv!item,
      local!nullKeys: reject(
        fn!isnull,
        a!forEach(
          items: a!keys(local!currentMap),
          expression: if(
            isnull(index(local!currentMap, fv!item, null)),
            fv!item,
            null
          )
        )
      ),
      remove(local!currentMap, local!nullKeys)
    )
  )
)

mikes0011
Brainy
August 26, 2025

It's not exactly documented but it was recently pointed out that the "remove()" function, classically thought of as removing an "index" as in an integer position within an array, can also be pointed at a named property and will "remove" that property from the result it outputs.  I believe it's a TINY bit "use at your own risk" still, but as it's a primitive function (iirc) I wouldn't worry too much about its behavior being dramatically impacted by any updates anytime soon (esp considering any alternate approaches to the same require a great deal of workaround).

Looks like [mention:9861aef97eb2483a8b76175d9eda1e37:e9ed411860ed4f2ba0265705b8793d05] has already posted you a working solution (even IF he used "index()" where i'd insist someone use "property()" [emoticon:dbebcc234b5646ae9035b59f9b586acd]).

August 26, 2025

This could also work:

a!localVariables(
  local!data: {
    a!map(
      ABC: 6.7,
      EFG: 15.44,
      HIJ: 470.888,
      KLM: "9.8989984",
      OPQ: null
    ),
    a!map(
      ABC: 8.4,
      EFG: 15.43,
      HIJ: 470.656,
      KLM: "9.2342",
      OPQ: null
    ),
    a!map(
      ABC: 7.2,
      EFG: 15.42,
      HIJ: 470.554,
      KLM: "9.234234",
      OPQ: null
    ),
    a!map(
      ABC: 5.6,
      EFG: 15.42,
      HIJ: 470.234,
      KLM: "9.63242",
      OPQ: null
    ),
    a!map(
      ABC: "",
      EFG: 15.42,
      HIJ: 470.665,
      KLM: "9.54343",
      OPQ: null
    )
  },
  a!forEach(
    items: local!data,
    expression: a!localVariables(
      local!item: fv!item,
      local!keysToRemove: a!forEach(
        items: a!keys(local!item),
        expression: if(
          a!isNullOrEmpty(index(local!item, fv!item, null)),
          fv!item,
          {}
        )
      ),
      remove(local!item, local!keysToRemove)
    )
  )
)