title: C# WebClient upload JSON in POST request
body: <p>I have some data in JSON format that I need to send to a web address via a POST request. The data resembles the following example:</p>
  
  <pre><code>[
   {
    "Id":0,
    "Name":"John"
   },
   {
    "Id":0,
    "Name": "James"
   }
  ]
  </code></pre>
  
  <p>I would normally have no problem uploading the data as a <code>NameValueCollection</code> using the <code>WebClient.UploadValues()</code> method:</p>
  
  <pre><code>using (WebClient Client = InitWebClient()) // InitWebClient() initialises a new WebClient and sets the BaseAddress and Encoding properties
  {
      NameValueCollection Values = new NameValueCollection
      {
          {"Id", "0"},
          {"Name", "John"}
      };
      Client.UploadValues("/api/example", "POST", Values);                
  }
  </code></pre>
  
  <p>However as this JSON request is a list (and must always be in the form of a list even if there is only one item being uploaded) I am at a loss as to how this is done.</p>
  
  <p>Due to programming constraints I need to do all of this using the WebClient object.</p>