title: What's causing JsonException: The JSON value could not be converted?
body: <p>C# 10 / .NET 6 / System.Text.Json</p>
  <p>I'm working with an API that returns as JSON response.  I'm trying to use <code>System.Text.Json</code> to deserialize the JSON response into a class.  I'm receiving a JsonException and could use help understanding what I'm doing wrong.</p>
  <p>I call the API and store the JSON response:
  <code>string json = await Retreive.Fetch(target);</code></p>
  <p>Here's the output of <code>Console.WriteLine(json)</code>:</p>
  <pre><code>[{&quot;id&quot;: 1148082,&quot;name&quot;: &quot;TestGroup&quot;,&quot;group_type&quot;:&quot;console_group&quot;,&quot;provisioning_guid&quot;: null,&quot;member_count&quot;: 1,&quot;current_risk_score&quot;: 36.3,&quot;status&quot;: &quot;active&quot;},{&quot;id&quot;: 1148788,&quot;name&quot;: &quot;Group2&quot;,&quot;group_type&quot;: &quot;smart_group&quot;,&quot;provisioning_guid&quot;: null,&quot;member_count&quot;: 9,&quot;current_risk_score&quot;: 39.7,&quot;status&quot;: &quot;active&quot;},{&quot;id&quot;: 1148792,&quot;name&quot;: &quot;Group3&quot;,&quot;group_type&quot;: &quot;smart_group&quot;,&quot;provisioning_guid&quot;: null,&quot;member_count&quot;: 9,&quot;current_risk_score&quot;: 39.7,&quot;status&quot;: &quot;active&quot;}]
  </code></pre>
  <p>Here's a pretty-printed version if it helps:</p>
  <pre><code>[
    {
      &quot;id&quot;: 1148082,
      &quot;name&quot;: &quot;TestGroup&quot;,
      &quot;group_type&quot;: &quot;console_group&quot;,
      &quot;provisioning_guid&quot;: null,
      &quot;member_count&quot;: 1,
      &quot;current_risk_score&quot;: 36.3,
      &quot;status&quot;: &quot;active&quot;
    },
    {
      &quot;id&quot;: 1148788,
      &quot;name&quot;: &quot;Group2&quot;,
      &quot;group_type&quot;: &quot;smart_group&quot;,
      &quot;provisioning_guid&quot;: null,
      &quot;member_count&quot;: 9,
      &quot;current_risk_score&quot;: 39.7,
      &quot;status&quot;: &quot;active&quot;
    },
    {
      &quot;id&quot;: 1148792,
      &quot;name&quot;: &quot;Group3&quot;,
      &quot;group_type&quot;: &quot;smart_group&quot;,
      &quot;provisioning_guid&quot;: null,
      &quot;member_count&quot;: 9,
      &quot;current_risk_score&quot;: 39.7,
      &quot;status&quot;: &quot;active&quot;
    }
  ]
  </code></pre>
  <p>Using Visual Studio 2022's Paste JSON As Classes function, I get the following class structure:</p>
  <pre><code>public class Rootobject
  {
      public Class1[] Property1 { get; set; }
  }
  
  public class Class1
  {
      public int id { get; set; }
      public string name { get; set; }
      public string group_type { get; set; }
      public object provisioning_guid { get; set; }
      public int member_count { get; set; }
      public float current_risk_score { get; set; }
      public string status { get; set; }
  }
  </code></pre>
  <p>I'm trying: <code>Rootobject? gag = JsonSerializer.Deserialize&lt;Rootobject&gt;(json);</code></p>
  <p>A JsonException is thrown:</p>
  <blockquote>
  <p>Unhandled exception. System.Text.Json.JsonException: The JSON value
  could not be converted to KB4.Rootobject. Path: $ | LineNumber: 0 |
  BytePositionInLine: 1.    at
  System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type
  propertyType)    at
  System.Text.Json.Serialization.Converters.ObjectDefaultConverter<code>1.OnTryRead(Utf8JsonReader&amp; reader, Type typeToConvert, JsonSerializerOptions options, ReadStack&amp; state, T&amp; value)    at System.Text.Json.Serialization.JsonConverter</code>1.TryRead(Utf8JsonReader&amp;
  reader, Type typeToConvert, JsonSerializerOptions options, ReadStack&amp;
  state, T&amp; value)    at
  System.Text.Json.Serialization.JsonConverter<code>1.ReadCore(Utf8JsonReader&amp; reader, JsonSerializerOptions options, ReadStack&amp; state)    at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan</code>1
  utf8Json, JsonTypeInfo jsonTypeInfo, Nullable<code>1 actualByteCount)    at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan</code>1
  json, JsonTypeInfo jsonTypeInfo)    at
  System.Text.Json.JsonSerializer.Deserialize[TValue](String json,
  JsonSerializerOptions options)    at KB4.Kb4.Main() in
  C:&lt;REDACTED&gt;\Program.cs:line 188    at
  KB4.Kb4.()</p>
  </blockquote>
  <p>Some things I have tried:</p>
  <ul>
  <li>Changing the name of the <code>Rootobject</code> class to <code>GetAllGroups</code></li>
  <li>Thinking the JSON may be somehow malformed in the response, I pasted it into a text file and load the JSON from there and then attempt deserialization again.</li>
  <li>Reviewed <a href="https://stackoverflow.com/questions/16856846/deserialize-a-json-array-in-c-sharp">Deserialize a JSON array in C#</a> but that's using JavaScriptSerializer.</li>
  </ul>
  <p>Neither of the above produces a different result.</p>
  <p>What am I doing wrong?</p>