title: Nested filtering with jq
body: <p>First time user of jq and I'm wanting to filter out objects based on a value within them and I'm struggling to figure it out.</p>
  
  <p>I have a big json file with lots of product data like what's below. I'm wanting to filter out based upon which website_ids they have.</p>
  
  <p>Example Input:</p>
  
  <pre><code>[{
      "product_id": "2",
      "sku": "PROD2",
      "name": "Product Name 2",
      "set": "4",
      "type": "simple",
      "category_ids": {
        "item": "15"
      },
      "website_ids": {
        "item": [
        "1",
        "4"
      ]}
  },{
      "product_id": "3",
      "sku": "PROD3",
      "name": "Product Name 3",
      "set": "4",
      "type": "simple",
      "category_ids": {
        "item": "15"
      },
      "website_ids": {
        "item": [
        "1",
        "2"
      ]}
  }]
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>[{
      "product_id": "2",
      "sku": "PROD2",
      "name": "Product Name 2",
      "set": "4",
      "type": "simple",
      "category_ids": {
        "item": "15"
      },
      "website_ids": {
        "item": [
        "1",
        "4"
      ]}
  }]
  </code></pre>
  
  <p>I've tried a few different things but I'm clearly just not getting it.</p>
  
  <p><code>jq 'map(.website_ids.item[] | contains("4"))'</code></p>
  
  <p>Gives me:</p>
  
  <pre><code>[
    false,
    true,
    false,
    false
  ]
  </code></pre>
  
  <p>Which seems to match the website_ids items I want, but I'm not sure how to get the full JSON object from that.</p>
  
  <p>Any help would be super appreciated! Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>I've used this and it works with my example:</p>
  
  <p><code>map(select(.website_ids.item[] | contains("4")))</code></p>
  
  <p>What I've realised is that my example and the file I was actually testing on have some differences.</p>
  
  <p>Sometimes a product has this for the website_id items:</p>
  
  <p>"website_ids": {
        "item": "2"
     }</p>
  
  <p>Which results in the error:</p>
  
  <p><code>Cannot iterate over string ("2")</code></p>
  
  <p>Is there a way around this?</p>