title: How to insert json array object in mysql diffrent columns using node js
body: <p>I have these values from json file
  &quot;histogram&quot;:{
  &quot;1&quot;:5708,
  &quot;2&quot;:838,
  &quot;3&quot;:1097,
  &quot;4&quot;:2964,
  &quot;5&quot;:26308
  }
  i wanted to insert them in mysql in column A,B,C,D,E respectively along with other data too i.e Date in node.js. on console i got the output right as i parse and stringify json. but it gives error &quot;Column count doesn't match value count at row 1&quot;. Any help will be highly appreciated.
  NOTE: I am new to node so my code wont be good enough.</p>
  <pre><code>var dbCon = require('./db'); 
  ////////// necessary node modules////////
  
  var readline = require('readline');
  var stream = require('stream');
  const utf8 = require('utf8');
  ///////////creating file stream to read a file/////////
  var fs = require('fs');
  var data1 = '';
  
  // Create a readable stream
  var request = require(&quot;request&quot;);
  var readerStream = fs.createReadStream('app.json');
  
  // Set the encoding to be utf8. 
   readerStream.setEncoding('UTF8');
  
   var outstream = new stream();
   //createInterface - read through the stream line by line and print out data from it
   var r1 = readline.createInterface(readerStream, outstream);
   var lineCount = 0;
  
  r1.on('line', function (line) {
   // increment line count
   lineCount++;
   data1 = JSON.parse(line);
   saveRecord(data1);
   });
  
  
   function saveRecord(data1) { 
   var histogram=data1[&quot;histogram&quot;] ; 
   var id=data1[&quot;id&quot;] ; 
   var datetime = new Date();
   var histogramstring= JSON.stringify(histogram) ;
   var sqlq1 = &quot;INSERT INTO wp_histo1(`id`,`A`,`B`,`C`,`D`,`E`,`Date`) VALUES (?,?,?)&quot;  ;
   dbCon.query(sqlq1,[ id,histogramstring,datetime]);
  
  
    console.log('data inserted');
    }
  
  
     console.log(&quot;Program Ended&quot;);  
  </code></pre>
  <p>Here is my console output.</p>
  <pre><code>code: 'ER_WRONG_VALUE_COUNT_ON_ROW',
   errno: 1136,
   sqlMessage: &quot;Column count doesn't match value count at row 1&quot;,
   sqlState: '21S01',
   index: 0,
   sql: 'INSERT INTO wp_histo1(`id`,`A`,`B`,`C`,`D`,`E`,`Date`) VALUES 
   (\'03125\',\'{\\&quot;1\\&quot;:5708,\\&quot;2\\&quot;:838,\\&quot;3\\&quot;:1097,\\&quot;4\\&quot;:2964,\\&quot;5\\&quot;:26308}\',\'2021-02-02 15:45:25.326\')'
  }
  </code></pre>
  <p>On the other hand if i try this query</p>
  <pre><code>  var sqlq1 = &quot;INSERT INTO wp_histo1(`id`,`A`,`Date`) VALUES (?,?,?)&quot;  ;
    dbCon.query(sqlq1,[ id,histogramstring,datetime]);
  </code></pre>
  <p>Full histogram array get inserted in to column A. But i wanted to split it in A,B,C,D,E column.</p>