Invisible characters breaking your JSON
When JSON looks perfectly correct but will not parse, the cause is usually a character you cannot see: a byte order mark, a non-breaking space or a zero-width character.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- A byte order mark is an invisible character some editors write at the start of a UTF-8 file. It sits before the opening brace and makes the document invalid.
- A non-breaking space looks exactly like a space but is not one of the four characters JSON allows as whitespace. Copying from a web page, a PDF or a word processor introduces them.
- Zero-width spaces and joiners can be pasted from documentation and chat clients and are completely invisible in most editors.
Example
{
"name": "My Mosaic"
}
{
"name": "My Mosaic"
}
How this tool reports it
The formatter names these specifically rather than reporting an unhelpful unexpected character, tells you it looks like a space but is not, and offers to replace it. A byte order mark is skipped silently, because it is never what the author meant to include.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- In your editor, save as UTF-8 without BOM. In Notepad this is a separate option from plain UTF-8.
- If a document looks correct and still will not parse, retype the line rather than staring at it.