title: Inserting multiple rows from JSON structure to MySQL
body: <p>I'm stuck with inserting JSON data to MySQL db using NodeJS.
  I got this error:</p>
  
  <blockquote>
    <p>Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''[{\"id\":\"d3f3d\",\"code\":\"' at line 1</p>
  </blockquote>
  
  <p>I'm getting JSON data from <code>url.json</code> using the <code>request</code> Node module and I'm trying to store the data in a MySQL db. </p>
  
  <pre><code>//mysql connection setup
  var connection = mysql.createConnection({
      host : "localhost",
      port: "3306",
      user : "root",
      password : "root",
      database : "db",
      multipleStatements: true
  });
  
  request('url.json', function (error, response, body) {
    if (!error &amp;&amp; response.statusCode == 200) {
      //console.log(body)
    }
  
      var sql = "INSERT INTO table (id, code, country_name, city) VALUES ?";
  
      var data = JSON.parse(body);
      var responseJson = JSON.stringify(data.response.docs);
  
      var query = connection.query(sql, [responseJson], function(err, result) {
          if(err) throw err;
          console.log('data inserted');
      });
      console.log(query.sql);
  
  });
  </code></pre>
  
  <p>The data is logged as <strong>''</strong> <code>'[{\"id\":\"d3f3d\",\"code\":\"'... }]'</code>. I think this may be the source of the error.</p>
  
  <p>JSON structure looks like this:</p>
  
  <pre><code>{
      "header":
      {
          "file1":0,
          "file2":1,
          "subfiles":{
            "subfile1":"true",
            "subfile2":"true",
          }
      },
  
      "response":
      {
          "number":678,
          "start":0,
          "docs":[
              {
                  "id":"d3f3d",
                  "code":"l876s",
                  "country_name":"United States",
                  "city":"LA"
              },
              {
                  "id":"d2f2d",
                  "code":"2343g",
                  "country_name":"UK",
                  "city":"London"
              }
          ]
      }
  }
  </code></pre>
  
  <p>How do I resolve this?</p>
  
  <p>Thanks.</p>