title: How to store a key and value in a table from a JSON object in MySQL
body: <p>I'm having a MySQL database tables namely ds_message and ds_params, it table ds_message contains a JSON object in each row. I would like to store the key and value of a JSON object into the table ds_params for all the records by referring the ds_message primary key <code>id</code></p>
  
  <p>Table: ds_message</p>
  
  <pre><code>_____________________________________________________________________________________
  id  key_value
  _____________________________________________________________________________________
  1  '{"a":"John", "b":"bat", "c":"$10"}'
  2  '{"i":"Emma", "j":"Jam"}'
  </code></pre>
  
  <p>I'm required to insert the key_value into another table like</p>
  
  <pre><code>_________________________________________________
  id   message_id    json_key    json_value
  _________________________________________________
  1    1             'a'         'John'
  2    1             'b'         'bat'
  3    1             'c'         '$10'
  4    2             'i'         'Emma'
  5    2             'j'         'Jam'
  </code></pre>
  
  <p><strong><em>Table Structure:</em></strong></p>
  
  <pre><code>CREATE TABLE `ds_message` (
    `id` int NOT NULL,
    `key_value` varchar(500) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='';
  
  ALTER TABLE `ds_message`
    ADD PRIMARY KEY (`id`);
  
  INSERT INTO `ds_message` (`id`, `key_value`) VALUES
  (1, '{"a":"John", "b":"bat", "c":"$10"}');
  
  INSERT INTO `ds_message` (`id`, `key_value`) VALUES
  (2, '{"i":"Emma", "j":"Jam"}');
  
  CREATE TABLE `ds_params` (
    `id` int NOT NULL,
    `message_id` int NOT NULL,
    `json_key` varchar(500) NOT NULL,
    `json_value` varchar(500) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='';
  
  ALTER TABLE `ds_params`
    ADD PRIMARY KEY (`id`);
  </code></pre>
  
  <p>Kindly assist me how to achieve this, it may be a simple select cum insert statement or by stored procedure in an optimized way.</p>