Code - Filter entry / Key / Value of a JSON object

Question related to filter the following json i got out of my google sheet mapping. I would like to filter out the empty entry. So in the below example, I would like to filter out FOO as there is empty value.


Apologies if this is trivial but i’m really struggling and i found filter for KEY > Value {} but it seeem that for my case i’m having an array {} and and object with key values but I’m still not very sure.
I tried to use javascript - How can I access and process nested objects, arrays, or JSON? - Stack Overflow as guidance for the code element in n8n but no success so far.

this is the code is have so far which doesn’t change the current structure.

obj = $input.all()
let output = Object.values(obj)
  for(let k in output)
    if( output[k] == "" )
      delete Object.values(output)
return output

Hey @mraniki,

Welcome to the community :tada:

It isn’t pretty but give this a go.

1 Like

Works like a charm. :grinning:
Thank you so much. :+1:
so if i understand your code it is item part of an array [] and property part of the object {} ? so there is no really key per say to filter.

Hey @mraniki,

You mostly got it :raised_hands: We have a bit on the data structure here: Data structure - n8n Documentation if you are interested.

1 Like

Thanks a lot for your prompt help and explanation.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.