JSON Errors / VS Code
End of file expected.How to Fix: End of file expected.
A JSON file must contain exactly one root value - one object or one array. VS Code reports "End of file expected." at the first character after that value ends, because it expected the file to stop there.
The red squiggle sits on whatever comes after the root: a second object, a stray closing brace, or the second line of a JSON Lines file. Everything before it parsed fine.
Common causes
1. Two objects in one file
Common after pasting or appending records. Wrap them in an array and separate them with a comma.
{ "id": 1, "name": "Ada" }
{ "id": 2, "name": "Alan" }[
{ "id": 1, "name": "Ada" },
{ "id": 2, "name": "Alan" }
]2. An extra closing brace or bracket
An edit left one } or ] too many, so the root closes early and the rest of the file looks like trailing content. Fold the root in VS Code (Ctrl+Shift+[ / Cmd+Option+[) to see where it really ends.
{
"server": { "port": 8080 }
}
}3. A JSON Lines file saved as .json
Log exports, OpenAI fine-tuning data, and BigQuery exports put one JSON object per line. That is valid JSON Lines but not valid JSON. Rename the file to .jsonl or .ndjson - VS Code has a built-in JSON Lines mode that validates each line separately.
How to fix it
# jq: read each line as a value and collect them into one array
jq -s '.' data.jsonl > data.json
# or in Node
const fs = require("fs");
const rows = fs.readFileSync("data.jsonl", "utf8")
.split("\n").filter(Boolean).map(line => JSON.parse(line));
fs.writeFileSync("data.json", JSON.stringify(rows, null, 2));# jq reports the problem with a line and column
jq . config.json
# Node gives the same error as Chrome:
# "Unexpected non-whitespace character after JSON at position 27"
node -e 'JSON.parse(require("fs").readFileSync("config.json", "utf8"))'Frequently asked questions
The file works in my app. Why does VS Code complain?
Your app may read the file line by line (JSON Lines) or with a lenient parser. VS Code validates .json files as a single strict JSON document. Either change the file to one root value or give it the extension that matches its real format: .jsonl for JSON Lines, .jsonc for JSON with comments.
How do I change the language mode without renaming?
Click the language name in the status bar (bottom right, "JSON") and pick "JSON Lines" or "JSON with Comments". This changes how VS Code validates that file only; for a permanent mapping add a files.associations entry in settings.
What does JavaScript say for the same problem?
JSON.parse in Chrome and Node throws "Unexpected non-whitespace character after JSON at position N", where N is the same position VS Code underlines. Python's json.loads raises "Extra data", covered in our JSONDecodeError extra data guide.
Last updated:
Related JSON errors
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →