I have a field, Ports, that is in arrays and is nested.
Examples of my data
"ports": ["TCP1", "TCP2", 'TCP3"]
"ports": ["UDP1", "UDP2"]
However each of these feeds have different number of elements in them. I have to strip the array brackets through the mutate replace filter but before that I need a ruby filter to retrieve the number of elements for each feed for a if-else check.
Desired Output:
filter {
     ruby {
         code => ??? Need help here with the code
     }
 
      mutate {
          if [number of elements] == 3 {
              replace => ["ports", "%{[port][0]} %{[port][1]} %{[port][2]}"]
          }
          else if [number of elements] == 2 {
              replace => ["ports", "%{[port][0]} %{[port][1]}"]
          }
        }
      }