title: An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartArray' node was expected
body: <p>I have an Azure AD Application where I need to add an extra appRole in the appRoles section within the service principal with Powershell. I use an Invoke-RestMethod to the Graph API with the following API Url: <a href="https://graph.microsoft.com/beta/servicePrincipals/AppID" rel="nofollow noreferrer">https://graph.microsoft.com/beta/servicePrincipals/AppID</a></p>
  
  <p>The Invoke-RestMethod returns an PSCustomObject, and then I add another PSCustomObject in the appRoles section. I then convert the PSCustomObject to JSON and want to write back the JSON to the service principal. The problem is when I want to write the JSON back to the service principal I get the error message: </p>
  
  <blockquote>
    <p>Invoke-RestMethod : The remote server returned an error: (400) Bad Request.</p>
  </blockquote>
  
  <p>I've tried to do this also with the Graph explorer and then I get the error message: </p>
  
  <blockquote>
    <p>"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartArray' node was expected."</p>
  </blockquote>
  
  <p>I think the same problem is also here in C#: <a href="https://stackoverflow.com/questions/42808408/getting-bad-request-error-while-updating-email-category-with-office-365-api-and/42839806#42839806">Getting Bad Request error while updating email category with Office 365 API and HttpClient in C#</a> </p>
  
  <p>When I do a Get in Graph Explorer the every appRole is displayed like this: </p>
  
  <pre><code>{
    "allowedMemberTypes": [
      "User"
    ],
    "description": "TEST-ALLOWALL",
    "displayName": "TEST-ALLOWALL",
    "id": "00000000-0000-0000-0000-00000000",
    "isEnabled": true,
    "origin": "ServicePrincipal",
    "value": "ARNROLEVALUE"
  },
  </code></pre>
  
  <p>When I do an Invoke-RestMethod and then ConvertTo-Json, every appRole is displayed like this:</p>
  
  <pre><code>{
    "allowedMemberTypes":  "User",
    "description":  "TEST-ALLOWALL",
    "displayName":  "TEST-ALLOWALL",
    "id":  "00000000-0000-0000-0000-00000000",
    "isEnabled":  true,
    "origin":  "ServicePrincipal",
    "value":  "ARNROLEVALUE"
  },
  </code></pre>
  
  <p>How can I make sure the Invoke-RestMethod keeps the allowedMemberTypes value type an array/list like ["User"] instead of the value "User"?</p>
  
  <p>And how can I make my own PSCustomObject allowedMembertypes value and arraylist so I can add it to the service principal?</p>
  
  <p>This is the code I am using</p>
  
  <pre><code>$apiUrl = 'https://graph.microsoft.com/beta/servicePrincipals/000000-0000-0000-0000-00000000000'
  $Data = Invoke-RestMethod -Headers $graphAPIReqHeader -Uri $apiUrl -Method Get
  
  $obj = New-Object -TypeName PSObject
  $obj | Add-Member -MemberType NoteProperty -Name allowedMemberTypes -Value "User"
  $obj | Add-Member -MemberType NoteProperty -Name description -Value $RoleName
  $obj | Add-Member -MemberType NoteProperty -Name displayName -value $RoleName
  $obj | Add-Member -MemberType NoteProperty -Name id -value $Id
  $obj | Add-Member -MemberType NoteProperty -Name isEnabled -value "true"
  $obj | Add-Member -MemberType NoteProperty -Name origin -value "ServicePrincipal"
  $obj | Add-Member -MemberType NoteProperty -Name value -value $Value
  
  $Data.appRoles += $obj
  $NewJson = $Data | ConvertTo-Json
  $NewData = Invoke-RestMethod -Headers $graphAPIReqHeader -Uri $apiUrl -Body $NewJson -Method Patch -ContentType 'application/json' 
  
  </code></pre>