title: How to convert result of mysql stored procedure to JSON data in shell script?
body: <p>I would like to convert the result of MySQL stored procedure to JSON data and insert into another table. </p>
  
  <p>When trying to the varchar datatype its working fine but I need JSON or array kind of data.</p>
  
  <pre><code>call="CALL status(input1,@data1,@data2,@data3.......)
  select="select @data1, @data2, @data3.....;"
  
  output=$(mysql --user=root --password=xxx db &lt;&lt; eof 
  $call
  $select
  eof)
  
  mysql --user=root --password=xxx db &lt;&lt; eof  
  insert into sam values ('$output');
  eof
  </code></pre>
  
  <p>This is the output result but I need this output like JSON. How to construct as JSON and pass the value to insert query in MySQL.</p>
  
  <pre><code>@data1  @data2  @data3  @data4  @data5  @data6  ..................
  1213    1174    367 57  8   7398    39  .............
  </code></pre>
  
  <p>This is my stored procedure:</p>
  
  <pre><code>DELIMITER ;;
  
  CREATE PROCEDURE status(
   IN input1 INT,
   IN input2 INT,
   OUT data1 INT,
   OUT data2 INT,
   OUT data3 INT)
  
  BEGIN
  
  --  data1
  select count(*) INTO data1 from account where time &gt;=input1 and time &gt;=input2;
  
  -- data2
  SELECT SUM(if(status&gt;0,1,0)) INTO data2 from account where time &gt;=input1 and time &gt;=input2;
  
  -- data3
  SELECT SUM(if(status=0,1,0)) INTO data3 from account where time &gt;=input1 and time &gt;=input2;
  
  END
  
  ;;
  </code></pre>
  
  <p>How can i construct this output like JSON?? I'm new to this topic!!</p>