Code & data
How to Open a JSON File and Find Syntax Errors
A JSON file won't load and the error only says "unexpected token". Learn how to open JSON readably and track down the exact line that breaks it.
Updated · 3 min read
JSON looks simple, and that's exactly why its errors are frustrating. An app refuses to load its config, an API rejects your request body, and the message says something like Unexpected token } in JSON at position 4821. Here's how to open the file in a readable way and find the problem fast.
Opening a JSON file
A JSON file is plain text, so any editor can open it. But a 5 MB file on one line is unreadable in Notepad. Better options:
- A JSON viewer in the browser. Drop the file into the JSON viewer to get syntax highlighting, a collapsible tree and error checking at once. It works on any device and the file isn't uploaded.
- A code editor. VS Code, Sublime Text or Notepad++ highlight JSON and can format it.
- Firefox. Dragging a .json file into Firefox shows a built-in tree view.
The most common JSON syntax errors
JSON is much stricter than JavaScript. These cause most failures:
- Trailing commas.
{"a": 1, "b": 2,}is invalid. The comma after the last item must go. - Single quotes. Strings and keys need double quotes:
{'name': 'x'}is invalid. - Unquoted keys.
{name: "x"}works in JavaScript, not in JSON. - Comments.
//and/* */are not allowed in standard JSON. Some tools accept "JSON with comments", but a strict parser will reject them. - Missing commas between items, often after copy-pasting objects together.
- Unescaped characters inside strings: a raw line break, tab or a lone backslash in a Windows path like
"C:\temp"(it must be"C:\\temp"). - Special values.
NaN,Infinityandundefinedare not valid JSON.
Finding the exact line
Error messages from programs often give a character position instead of a line number, which is hard to use. A validator translates it:
- Open the JSON viewer and paste or drop the file.
- Look at the problem list. Each error shows line and column plus an explanation, such as "Trailing comma before }".
- Click the entry to jump to the spot in the editor and fix it.
- When the status turns to Valid, use Format to pretty-print the file and download it.
One tip: when a file has one missing bracket, the reported position is where the parser noticed the problem, which can be far below the actual mistake. Check the structure around the reported line, and use the tree view to see where nesting stops making sense.
The error that isn't reported: duplicate keys
{ "timeout": 30, "retries": 3, "timeout": 5 }
This is syntactically valid, but most parsers silently keep the last value, so your app uses a timeout of 5, not 30. A good viewer flags duplicates as warnings. Treat them as bugs.
Large JSON files
For big exports or logs, raw text is the wrong view:
- Tree view lets you collapse everything and expand only the branch you need. Copy the path of any value, like
$.orders[42].total, to use in code. - Table view turns an array of objects into rows and columns you can sort.
- JSON Lines files (
.jsonl, one object per line) should be validated line by line, so one broken record doesn't hide the rest.
Related formats
If the file is actually YAML or has comments, it isn't JSON. Use the YAML viewer for .yml configs, and the code viewer for anything else text-based.
Quick checklist for broken JSON
- No trailing comma after the last item in an object or array.
- All keys and strings in double quotes.
- No comments.
- Backslashes in strings doubled.
- Brackets and braces balanced.