title: Invalid UTF-8 JSON on CouchDB bulk document api
body: <p>I have a node console app where I am trying to post a number of record to the bulk document api on a local CouchDB instance and getting an "Invalid UTF-8 JSON." What makes this particularly odd, is that I'm generating my JSON using JSON.stringify on a object literal.</p>
  
  <p>I tested the actual json at <a href="http://jsonlint.com/" rel="nofollow">http://jsonlint.com/</a> and supposedly it's valid. I can't post the full json here as it's names and number from a directory, but I can show you a mock record to give you the basic structure.</p>
  
  <pre><code>{
   "family" : "Smith",
          "people":{
              "Bob":{
                   "name":"Bob", 
                   "active" : true,
                  "birthday" : "1/01"
              },
              "Sue":{
                  "name": "Sue", 
                  "active" : true,
                  "birthday" : "1/01"
              }
          },
          "address": {
              "street" :"1111 Cool Road",
              "city" : "Cincinnati",
              "state" : "OH",
              "zip" : "11111"
          },
          "phone" : "923-4908"            
  };
  </code></pre>
  
  <p>I wrapped my array of records in a json object with the property "docs" as specified <a href="http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API" rel="nofollow">here</a>. Is there anything obviously wrong with what I'm trying to do?</p>
  
  <p>UPDATE:
  Following lambmj's suggestion, I wrote the string generated by node out to a file and then used curl to post that to the bulk document upload. That worked perfectly. I'd still like someone to help me correct my node code though, so that it works from within node. Here's the exact code that builds and posts the request</p>
  
  <pre><code>  //The result variable is my array of 'family' objects, 
    //It's generated by parsing a text file, not show here
    var postOptions = {
    host: 'localhost',
    port: '5984',
    path: '/members/_bulk_docs',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': result.length
    }
  };
  var request = http.request(postOptions, function(res){
      res.setEncoding('utf8');
      res.on('data', function (chunk) {
        console.log('Response: ' + chunk);
      });
  });
  var body = { "docs": result};
  var stringData = JSON.stringify(body);
  console.log(stringData);
  request.write(stringData);
  </code></pre>