Find matching integers in JSON.
<p>I want to find 123 in a JSON string in MySQL. </p><p>This is my query:</p><p><br /></p>
<pre class="brush:php;toolbar:false;">SELECT *
FROM `reports`
WHERE JSON_CONTAINS(json_data, 123, "$.respCode");</pre>
<p>When I run this code I get the following error: </p>
<blockquote>
<pre class="brush:php;toolbar:false;">Error Code: 3146. Invalid data type for JSON data in argument 1 to
function json_contains; a JSON string or JSON type is required. 0.020 sec</pre>
</blockquote>
<p>My json looks like this in the json_data column: </p>
<pre class="lang-json prettyprint-override"><code>{ "bla":"", "bla2":"", "bla3":"", "bla4":"", "respCode ":"123", "bla5":"" }
</code></pre>
<p>I also tried this</p>
<p><code>WHERE JSON_UNQUOTE(JSON_EXTRACT('json_data', "$.respCode")) = '123'</code></p>