cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with list operation

Bhagya_pola
Executive Chef I
Executive Chef I

Currently I am trying to map  list  itemsScreenshot 2026-01-06 182121.png

 

Currently, when the entire list has no data, the output is generated in the following format:

{ "list": [{}, {}, {}] }

However, if the list is completely empty, I don’t want the array to appear at all in the output payload. The list field should be entirely omitted, with no empty objects or placeholders included.

Is there a workaround to conditionally exclude this field from the output when no data is present?

 
3 REPLIES 3

gary1
Star Chef I
Star Chef I

I've never found a simple solution for this problem, so I use a Ruby action with this code to recursively remove null/blank keys. Hopefully someone has a native or better way of doing this.

 

def deep_compact(obj)
  case obj
  when Hash
    obj.each_with_object({}) do |(k, v), h|
      cleaned = deep_compact(v)
      h[k] = cleaned unless cleaned.nil? || cleaned == ""
    end
  when Array
    obj.map { |v| deep_compact(v) }.reject { |v| v.nil? || v == "" }
  else
    obj
  end
end

 

Thank you, @gary1 
For ease of explanation, I have shown CDM here however, the actual scenario deals with SAP RFC – Send IDoc. CDM in this context refers to the SAP IDoc structure only and is used purely for representation. There is no downstream processing involved everything required must be handled entirely within the SAP step.

I don't think you can solve this issue in the input of the SAP step. You need to pre-process the data to remove the empty objects from the array (using the Ruby I provided) and then map the output of the Ruby action into the input of SAP step. 

I can't guarantee this will work for your exact situation, but it has worked for me in similar situations before.