title: Error "Token PropertyName in state ArrayStart would result in an invalid JSON object." when trying to serialize object
body: <p>This is the error</p>
  <pre class="lang-none prettyprint-override"><code>This exception was originally thrown at this call stack:
      Newtonsoft.Json.JsonWriter.AutoComplete(Newtonsoft.Json.JsonToken)
      Newtonsoft.Json.JsonWriter.InternalWritePropertyName(string)
      Newtonsoft.Json.JsonTextWriter.WritePropertyName(string)
      Newtonsoft.Json.Linq.JProperty.WriteTo(Newtonsoft.Json.JsonWriter, Newtonsoft.Json.JsonConverter[])
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(Newtonsoft.Json.JsonWriter, object, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(Newtonsoft.Json.JsonWriter, System.Collections.IEnumerable, Newtonsoft.Json.Serialization.JsonArrayContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(Newtonsoft.Json.JsonWriter, object, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(Newtonsoft.Json.JsonWriter, object, Newtonsoft.Json.Serialization.JsonObjectContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(Newtonsoft.Json.JsonWriter, object, Newtonsoft.Json.Serialization.JsonContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
      Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(Newtonsoft.Json.JsonWriter, System.Collections.IEnumerable, Newtonsoft.Json.Serialization.JsonArrayContract, Newtonsoft.Json.Serialization.JsonProperty, Newtonsoft.Json.Serialization.JsonContainerContract, Newtonsoft.Json.Serialization.JsonProperty)
  </code></pre>
  <p>It's thrown in this method:</p>
  <pre><code>public static void SaveSystemScans()
  {
       File.AppendAllText(StarSystemsDatabase, JsonConvert.SerializeObject(systemScans));
  }
  </code></pre>
  <p>I'm working on a programm to deserialize Json data from a file from a game. In the game, you can scan Star Systems, each of with contains multiple Stellar Bodies. These stellar Bodies have multiple different properties, which are represented in the code as <code>JProperty</code>. I believe the error might be occuring somewhere in the List of JProperties in a Stellar Object. I've manually checked each Property though and they seem fine. I was able to find some other Question related to this error, however none of the conclusively answered why this error is thrown. (Most of them were about either the <code>dynamic</code> type or Azure, which I'm both not using. Right now I'm just trying to reserialize the main List into JSON to read it again and to build a library of systems. I'm eventually planning to put them into a database.</p>
  <p>The object I'm trying to serialize looks like this:</p>
  <pre><code>private static Dictionary&lt;string, SystemScan&gt; systemScans = new Dictionary&lt;string, SystemScan&gt;();
  </code></pre>
  <p>Each SystemScan object contains a name and a <code>List&lt;StellarObjects&gt;</code> with all the StellarObjects of a system.
  The constructor for this class is fairly simple and looks like this:</p>
  <pre><code>public StellarObject(string jsonData)
  {
        Properties = JObject.Parse(jsonData).Properties().ToList();
        BodyName = JObject.Parse(jsonData)[&quot;BodyName&quot;].ToString();
  }
  </code></pre>
  <p>I'm not sure if this is valid to post here, but this is what the primary List looks like at the time of the exception:</p>
  <p><a href="https://i.stack.imgur.com/Qdj8M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qdj8M.png" alt="The structure of the object with properties." /></a></p>