title: MySQL JSON column add new array as element
body: <p>I have a table with JSON type column, I want to update a column with new array element in existing JSON.</p>
  
  <p><strong>What needs to be done:</strong> add an array in JSON column when employee punch_in and add another array in JSON column when employee punch_out.</p>
  
  <pre><code>{"emp_sheet":[{"rulecode":"PUNCH_IN","result":1,"applytime":"2018-04-12 04:50:39"},{"rulecode":"PUNCH_OUT","result":1,"applytime":"2018-04-12 13:01:39"}]}
  </code></pre>
  
  <p>What I did, for employee punch_in:</p>
  
  <pre><code>UPDATE table 
  SET rule_codes = JSON_SET(COALESCE(rule_codes, '{}'), '$.emp_sheet', '{"rulecode":"PUNCH_IN","result":1,"applytime":"2018-04-12 04:50:39"}') 
  WHERE emp_id = 1
  </code></pre>
  
  <p>Result in rule_codes column = </p>
  
  <p><code>{"emp_sheet": "{"rulecode":"PUNCH_IN","result":1,"applytime":"2018-04-12 04:50:39"}"}</code></p>
  
  <p>Please help me to write update query for employee punch_out.</p>