title: How to search nested JSON in MySQL
body: <p>I am using MySQL 5.7+ with the native JSON data type. Sample data:</p>
  
  <pre><code>[
    {
      "code": 2,
      "stores": [
        {
          "code": 100,
          "quantity": 2
        },
        {
          "code": 200,
          "quantity": 3
        }
      ]
    },
    {
      "code": 4,
      "stores": [
        {
          "code": 300,
          "quantity": 4
        },
        {
          "code": 400,
          "quantity": 5
        }
      ]
    }
  ]
  </code></pre>
  
  <p>Question: how do I extract an array where <code>code = 4</code>? </p>
  
  <p>The following (working) query has the position of the data I want to extract and the search criterion hardcoded:</p>
  
  <pre><code>SELECT JSON_EXTRACT(data_column, '$[0]') 
  FROM   json_data_table
  WHERE  data_column-&gt;'$[1].code' = 4
  </code></pre>
  
  <p>I tried using a wildcard (<code>data_column-&gt;'$[*].code' = 4</code>) but I get no results in return.</p>