title: How can I deserialize arrays/objects posted to my NodeJS/Express web app?
body: <p>I'm writing an app in NodeJS/ExpressJS.</p>
  
  <p>I have a form like this:</p>
  
  <pre><code>&lt;form method="post" action="/sendinfo"&gt;
      &lt;label&gt;Name&lt;/label&gt;
      &lt;input type="text" name="name" /&gt;
  
      &lt;label&gt;Address&lt;/label&gt;
      &lt;input type="text" name="address[number]" /&gt;
      &lt;input type="text" name="address[street]" /&gt;
      &lt;input type="text" name="address[suburb]" /&gt;
      &lt;input type="text" name="address[postcode]" /&gt;
  
      &lt;label&gt;Phones&lt;/label&gt;
      &lt;input type="text" name="phones[0]" /&gt;
      &lt;input type="text" name="phones[1]" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here's my route:</p>
  
  <pre><code>app.post('/sendinfo', function (req, res) {
  
      // ...code to save the contents of req.body to the database...
  
      res.render('done');
  });
  </code></pre>
  
  <p>When the form gets submitted, my <code>req.body</code> looks like this:</p>
  
  <pre><code>{
      "name": "Jonathan",
  
      "address[number]": "1",
      "address[street]": "Test St",
      "address[suburb]": "TestSuburb",
      "address[postcode]": "1234",
  
      "phones[0]": "12345678",
      "phones[1]": "87654321"
  }
  </code></pre>
  
  <p>But I want it to instead look like this, with the values nested inside properties or arrays:</p>
  
  <pre><code>{
      "name": "Jonathan",
  
      "address": {
          "number": "1",
          "street": "Test St",
          "suburb": "TestSuburb",
          "postcode": "1234",
      },
  
      "phones": [
          "12345678",
          "87654321"
      ]
  }
  </code></pre>
  
  <p>How can I do this?</p>