Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
JsonConvert.DeserializeObject was handed something that does not start with a JSON value. Line 0 position 0 means it failed on the very first character. The character named in the message tells you what you actually have.
Paste your JSON and see exactly where it breaks
Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself
What actually causes it
Ranked by how often each one turns out to be the answer.
-
01 You passed a file path instead of file content
DeserializeObject takes a JSON string, not a filename. Passing a path means the parser reads C:\... as the document and fails on the letter C or on a slash. This is a very common mistake and the message does not hint at it.
Breaks
var data = JsonConvert.DeserializeObject<Model>(@"C:\data\input.json");Works
var json = File.ReadAllText(@"C:\data\input.json"); var data = JsonConvert.DeserializeObject<Model>(json); -
02 The response is HTML
An error page, a login redirect or an IIS error. The character in the message will be <. Read the body as a string and inspect it before deserialising.
Breaks
var data = JsonConvert.DeserializeObject<Model>(await res.Content.ReadAsStringAsync());Works
var body = await res.Content.ReadAsStringAsync(); if (!res.IsSuccessStatusCode || !body.TrimStart().StartsWith("{")) throw new InvalidOperationException($"{(int)res.StatusCode}: {body[..Math.Min(300, body.Length)]}"); var data = JsonConvert.DeserializeObject<Model>(body); -
03 A byte order mark at the start of the string
Reading a file without letting the encoding detector strip the BOM leaves U+FEFF in front of the JSON.
The same mistake in other runtimes
The underlying problem is identical; only the wording differs. If a colleague reports one of these, they are looking at the same thing you are.
| C# (System.Text.Json) | '<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. |
|---|---|
| JavaScript (V8) | Unexpected token '<', "<!DOCTYPE "... is not valid JSON |
Questions
- Should I migrate to System.Text.Json?
- It is the built-in option from .NET Core 3.0 onwards and is faster, but it is also stricter: no single-quoted strings, no trailing commas, no comments unless you enable them explicitly. Code that relied on Newtonsoft being forgiving will need the producer fixed.
Fix it now
Paste the payload into the tool above, or go straight to the one built for this job.
Check the payload