title: Trying to send a nested JSON through a HTTP 'POST' request in Javascript
body: <p>I'm trying to send an array of json objects to a local server by an HTTP 'POST' request. I've been using an npm module found here: <a href="https://www.npmjs.com/package/request" rel="nofollow noreferrer">https://www.npmjs.com/package/request</a> to do the request. I've done this before and for the most part my code works fine, but I have an issue I've been unable to resolve.</p>
  
  <pre><code>var request = require('request');
  const obj = require('./bugs.json');
  
  obj.forEach(element =&gt; {
      // Set the headers
    var headers = {
      'Content-Type': "stuff",
      'x-authorization': "stuff"
    }
  
    // Configure the request
    var options = {
        url: 'http://localhost:8080/bugreport/import',
        method: 'POST',
        headers: headers,
        form: {
            'subject': element.subject,
            'description': element.description,
            'platform': element.platform,
            'date': element.date,
            'author': element.author,
            'isSolved': element.isSolved,
            'createdAt': element.createdAt,
            'updatedAt': element.updatedAt,
            'id': element.id
        }  
    }
  //
    // Start the request
    request(options, function(error, response, body){
        if (!error &amp;&amp; response.statusCode == 200) {
            console.log("No error detected.");
            console.log(body)
        }
        else {
            console.log("Error: " + error);
        }
    })
  
  });
  </code></pre>
  
  <p>The problematic line is <code>'author': element.author,</code>  While every other attribute is a basic data type, author is itself a nested json. Here is what the json file looks like:</p>
  
  <pre><code>[
      {
      "subject": "Bug",
      "description": "Testing brscript",
      "platform": "A",
      "date": "2/15/2018",
      "author": [
          {
              "username": "testuser1",
              "firstName": "test",
              "lastName": "user1",
              "password": "password",
              "admin": false,
              "isVisible": true,
              "isDeleted": false,
              "createdAt": "2018-02-08T18:42:58.473Z",
              "updatedAt": "2018-02-13T15:51:17.954Z",
              "id": 170
          }
      ],
      "isSolved": false,
      "createdAt": "2/15/2018",
      "updatedAt": "2/15/2018",
      "id": 999
      }
  ]
  </code></pre>
  
  <p>As I said, I've done this before, but not with a nested json as one of my attributes. Everything but the author json will send. So, there must be something wrong with my syntax. I've tried several different approaches to get it to recognize the json, but none have worked.</p>