title: Filtering a nested json for a particular flied and returning adjacent member in ruby
body: <p>I have an API response of the following structure</p>
  <pre><code>{
    &quot;id&quot;: &quot;123342-123412&quot;,
    &quot;data&quot;: [
      {
        &quot;id&quot;: &quot;ace123&quot;,
        &quot;name&quot;: &quot;Tom&quot;,
        &quot;files&quot;: [
          {
            &quot;color&quot;: &quot;yellow&quot;,
            &quot;file_id&quot;: &quot;245&quot;
          },
          {
            &quot;color&quot;: &quot;red&quot;,
            &quot;file_id&quot;: &quot;233&quot;
          }
        ]
      },
      {
        &quot;id&quot;: &quot;asd123&quot;,
        &quot;name&quot;: &quot;Jerry&quot;,
        &quot;files&quot;: [
          {
            &quot;color&quot;: &quot;red&quot;,
            &quot;file_id&quot;: &quot;210&quot;
          },
          {
            &quot;color&quot;: &quot;green&quot;,
            &quot;file_id&quot;: &quot;221&quot;
          }
        ]
      },
      {
        &quot;id&quot;: &quot;acs123&quot;,
        &quot;name&quot;: &quot;Barbie&quot;,
        &quot;files&quot;: [
          {
            &quot;color&quot;: &quot;green&quot;,
            &quot;file_id&quot;: &quot;201&quot;
          }
        ]
      }
    ]
  }
  </code></pre>
  <p>I am new to ruby, I want to filter out all file ids with the color <strong>red</strong>, what's the better way of doing it rather than iterating through the whole JSON using</p>
  <pre><code>data.each do  | object| 
  # individual element search code 
  end
  </code></pre>
  <p>I am using ruby version 2.6</p>