You ask a model for JSON, it gives you something that looks like JSON, and your code throws:
SyntaxError: Unexpected token 'H', "Here is th"... is not valid JSON
or in Python:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2
The data is usually fine. The wrapping and a few small syntax habits are not. Below are the mistakes that cause almost every failure, how to recognise each one from the error, and how to stop them happening.
The six usual mistakes
1. Text around the data
Chat models are trained to be conversational, so they often add "Here is the JSON you asked for:" before the data or "Let me know if you need changes!" after it. A parser reads the first character, finds an H instead of {, and gives up immediately. An error mentioning an unexpected letter at position 0 almost always means this.
2. Markdown code fences
In a chat interface, JSON is usually shown inside a code block. When you copy the raw response from an API, you get the fence characters too: three backticks and the word json on the first line. The error points at an unexpected backtick.
3. Trailing commas
["a", "b",] is legal in JavaScript and Python, but not in JSON. Models produce it often, especially in long lists. The error usually says something like "Unexpected token ]" or "Expecting value".
4. Single quotes and unquoted keys
{name: 'Ana'} is a valid JavaScript object and a valid Python dict, but JSON requires double quotes around every key and every string. Python's error message, "Expecting property name enclosed in double quotes", names this one directly.
5. Python and JavaScript values
True, False and None are Python. undefined, NaN and Infinity are JavaScript. JSON only knows true, false and null, and has no way to store NaN or infinity at all. These creep in when a model has just been writing code in the same conversation.
6. Output cut off part way
If a response reaches the model's output limit, it simply stops, often in the middle of a string. The error then points at the very end of the input. Depending on your browser or Node version, it reads "Unexpected end of JSON input", "Unterminated string", or "Expected ',' or '}' after property value" with a position equal to the length of the text. This is the only mistake where information is actually lost, because the model never wrote the rest.
Reading the position in the error
Most parsers tell you where they gave up, as a character position or a line and column. That position is where the parser noticed a problem, which is usually just after the real mistake. Look at the character there and the few before it:
| Error mentions | Likely cause |
|---|---|
| Position 0, or an unexpected letter | Text before the data |
| An unexpected backtick | Code fence |
] or } right after a comma |
Trailing comma |
| "property name" or a single quote | Unquoted key or single quotes |
| An unexpected T, F or N mid-object | Python True, False or None |
| End of input, unterminated string, or a position at the very end | Cut-off output |