Alter an existing MySQL column to a JSON data type
<p>I am trying to change a MySQL column from varchar(9000) NULL to the new JSON data type in MySQL 5.7. The column holds valid JSON strings but some values are null. When I try the following:</p>
<pre><code>alter table log modify request json
</code></pre>
<p>it fails with the following error:</p>
<pre><code>Invalid JSON text: &quot;The document is empty.&quot; at position 0 in value for column '#sql-2f36_168a6.request'
</code></pre>
<p>However, when I create a new column:</p>
<pre><code>alter table log add request_json json
</code></pre>
<p>and then insert the same data:</p>
<pre><code>update log set request_json=json where request != ''
</code></pre>
<p>the new request_json column is updated.  How to I modify the existing column to JSON data type and preserve the JSON data without creating a new column?</p>