title: MySQL: How to insert into the middle of JSON
body: <p>Say I have JSON stored in MySQL as JSON type:</p>
  
  <pre><code>{"key1":"value1","key3":"value3","key2":"value2"}
  </code></pre>
  
  <p>and I want to insert "key4":"value4" at a specific position, e.g.:</p>
  
  <pre><code>{"key1":"value1",   "key4":"value4"   ,"key3":"value3","key2":"value2"}
  </code></pre>
  
  <p>Is there purely a MySQL command to do this?</p>
  
  <p>JSON_INSERT looks to only be able to append to JSON.</p>
  
  <p>I'd rather do it as a MySQL command to keep it efficient, otherwise, I would have to pull the entire JSON string out, decode it, do some PHP commands, and then restore it. Seems like there should be a MySQL way of saying put this in at index 2 or so.</p>
  
  <p>Any guidance would be appreciated.</p>