title: Post nested objects in query string - Node.js
body: <p>My code is attempting to post data to a Coldfusion API from my local Node.js server. I have managed to communicate with the API and authenticate myself via the request headers. However I am having difficulty actually passing my JSON object through as I cannot get the structure right.</p>
  
  <p>The API does not accept the JSON option of the request module, so that is my easiest option out of the window. </p>
  
  <p>The API is expecting the following:</p>
  
  <pre><code>{ 
      'source': { 
          'customer': {
              'customerlogin': 'myusername',
              'customerpassword': 'mypassword',
           }
       }
  }
  </code></pre>
  
  <p>my code works if I hard code the following body parameter (from a sucessful post by somebody else) into my post. </p>
  
  <pre><code>var Jrequest = require('request');
  
  var options = {
    uri: 'http://myAPI/customerSSO.json',
    headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': something', 'Timestamp': timestamp},
    method: 'POST',
    body: 'source=%7B%0D%0A++%22customer%22%3A+%7B%0D%0A++++%22customerlogin%22%3A+%22myusername%22%2C%0D%0A++++%22customerpassword%22%3A+%22mypassword%22%2C%0D%0A%09%22success%22%3A+%22%22%0D%0A++%7D%0D%0A%7D' // Working
  };
  
  
  Jrequest(options, function (error, response, body){
      res.send(body);
  });
  </code></pre>
  
  <p>If I send the JSON through in other ways, for example json.stringify(), it is rejected on the grounds that 'source is required but not defined'. </p>
  
  <p>So I suppose my question is, in node.js how do I turn JSON into something that looks like this </p>
  
  <pre><code>'source=%7B%0D%0A++%22customer%22%3A+%7B%0D%0A++++%22customerlogin%22%3A+%22myusername%22%2C%0D%0A++++%22customerpassword%22%3A+%22mypassword%22%2C%0D%0A%09%22success%22%3A+%22%22%0D%0A++%7D%0D%0A%7D'
  </code></pre>
  
  <p>or have I overlooked another option?</p>
  
  <p>Thanks for any help and apologies if I have used incorrect terminology.</p>