title: Unexpected character encountered while parsing value ASP.NET Core and Newtonsoft
body: <p>I am trying to parse a JSON file into an object using Newtonsoft in my ASP.NET Core application but I keep getting this error:</p>
  <blockquote>
  <p>Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: {. Path 'palette.swatch', line 7, position 15.'</p>
  </blockquote>
  <p>I've tried using the <code>StreamReader</code> class and now <code>MemoryStream</code> class. I've confirmed validated the JSON online and checked it is UTF-8 too. Both ways I receive the same error. I also manually checked the JSON but I can't see anything that would make it unreadable.</p>
  <p>Here's the method that is throwing the exception:</p>
  <pre><code>public async Task&lt;int&gt; PostDefinition(IFormFile file)
  {
      MemoryStream ms = new MemoryStream();
      file.CopyTo(ms);
      byte[] bytes = ms.ToArray();
      string s = Encoding.UTF8.GetString(bytes);
  
      Definition definition = Newtonsoft.Json.JsonConvert.DeserializeObject&lt;Definition&gt;(s);
      Definition x = ObjectMapper.Map&lt;Definition&gt;(Definition);
  
      return await _definitions.InsertAndGetIdAsync(x);
  }
  </code></pre>
  <p>This is the segment of the JSON that is throwing an error:</p>
  <pre><code>{
    &quot;name&quot;: &quot;Definition&quot;,
    &quot;id&quot;: 2,
    &quot;palette&quot;: {
      &quot;name&quot;: &quot;Test Palette&quot;,
      &quot;default&quot;: false,
      &quot;swatch&quot;: {
        &quot;colors&quot;: {
          &quot;Color 1&quot;: &quot;transparent&quot;,
          &quot;Color 2&quot;: &quot;transparent&quot;,
          &quot;Color 3&quot;: &quot;transparent&quot;,
          &quot;Color 4&quot;: &quot;transparent&quot;,
          &quot;Color 5&quot;: &quot;transparent&quot;,
          &quot;Color 6&quot;: &quot;transparent&quot;,
          &quot;Color 7&quot;: &quot;transparent&quot;,
          &quot;Color 8&quot;: &quot;transparent&quot;
        }
      }
    }
  }
  </code></pre>
  <p>What could be causing the exception and what can I try to remedy it? I've tried searching and nothing I try seems to work.</p>