title: How to convert indexed collection from FormCollection to JSON array in C#
body: <p>I am currently working on an ASP.NET Core MVC project and I am facing a problem with binding collections from IFormCollection to a JSON array.</p>
  
  <p>Currently I have a web application that passes data from an IFormCollection through to other Web API microservices.</p>
  
  <p>So, my form collection might look something like this pseudocode:</p>
  
  <pre><code>People[0].Name="Jon Skeet"&amp;People[1].Name="SLaks"
  </code></pre>
  
  <p>When it is posted to my MVC controller as an IFormCollection, it pretty much looks the same, where the keys are "People[0].Name", "People[1].Name" and the values are "Jon Skeet" and "SLaks".</p>
  
  <p>This is problematic because when I eventually serialize to JSON, instead of getting this:</p>
  
  <pre><code>{ People: [ { Name: "Jon Skeet" }, { Name: "SLaks"} ] }
  </code></pre>
  
  <p>I get this instead:</p>
  
  <pre><code>{ "People[0].Name": "Jon Skeet", "People[1].Name": "SLaks" }
  </code></pre>
  
  <p>Which does not bind to <code>[FromBody]IEnumerable&lt;Person&gt; People</code> when I post from my MVC controller to my microservice's controller for obvious reasons.</p>
  
  <p>So, my question is, how can I get my IFormCollection to serialize to JSON in such a way that indexed collections serialize properly to a JSON array? Is there some kind of custom converter or something else I need to implement in order to make it work?</p>
  
  <p>Please note that my MVC controller must take an IFormCollection because it acts as a catch-all controller that routes to the proper microservice based on the Request URL.</p>