title: Powershell Invoke-Webrequest w/ JSON Body - Can not deserialize...?
body: <p>I need to perform an Invoke-Webrequest with a specifically formatted body to add devices to a product. Here is what it looks like in json (example straight from the vendor's documentation):</p>
  
  <pre><code>$body_json = '{"datasource": [{
              "parentId": "123456789000",
              "name": "(name)",
              "id": "(value)",
              "typeId": 0,
              "childEnabled": false,
              "childCount": 0,
              "childType": 0,
              "ipAddress": "(ipAddress)",
              "zoneId": 0,
              "url": "(url)",
              "enabled": false,
              "idmId": 123456789000,
              "parameters": [{
                  "key": "(key)",
                  "value": "(value)"
              }]
          }]}'
  </code></pre>
  
  <p>When I try to submit this in its json representation though, I get the following error:</p>
  
  <blockquote>
    <p>Invoke-WebRequest : Can not deserialize instance of
    com.vendor.etc.DataSourceDetail out of START_ARRAY token at [Source: 
    java.io.StringReader@22c614; line: 1, column: 1] At
    C:\powershell_script_location\ps.ps1:114 char 9
    + $request = Invoke-WebRequest $url -Method Post -Headers $headers -Body $body_json - ...
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo              : InvalidOperation:
    (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],
    WebException  + FullyQualifiedErrorId :
    WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand</p>
  </blockquote>
  
  <p>The issue is with the format of the "parameters", parameter because the request submits fine when omitting the "parameters", but then the 
  devices that I'm adding are missing important parameter details. </p>
  
  <p>Is there something wrong with <code>Invoke-WebRequest, JavaScriptSerializer,</code> 
  the vendor's code, or is this a user error? Let me know if any clarification is needed.</p>
  
  <p>Unfortunately I don't know what a <code>com.vendor.etc.DataSourceDetail</code> instance looks like, as I am using an API and I don't have access to it directly.</p>