The EJSONPARSE error occurs when npm encounters invalid JSON in package.json or another JSON configuration file. This is usually caused by syntax errors like missing commas, brackets, or quotes.
Fixes npm ERR! code EJSONPARSE
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234npm install# Output shows:# npm ERR! JSON.parse Failed to parse json# npm ERR! JSON.parse Unexpected token } in JSON at position 234npm ERR! code EJSONPARSE
On this page
EJSONPARSE indicates that npm failed to parse a JSON file, most commonly package.json. JSON has strict syntax requirements - even small errors like a trailing comma, missing quote, or extra bracket will cause parsing to fail. This error can occur in package.json, package-lock.json, .npmrc, or any other JSON file that npm tries to read during its operation.
Read the error message carefully:
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234The position helps locate the error.
Use a JSON validator:
# Using jq
jq . package.json
# Using Node.js
node -e "require('./package.json')"
# Or use online validators like jsonlint.comJSON doesn't allow trailing commas:
// WRONG
{
"name": "pkg",
"version": "1.0.0", // <-- trailing comma ERROR
}
// CORRECT
{
"name": "pkg",
"version": "1.0.0"
}JSON doesn't support comments:
// WRONG
{
// This is a comment - NOT ALLOWED
"name": "pkg"
}
// CORRECT - no comments
{
"name": "pkg"
}JSON requires double quotes:
// WRONG
{
'name': 'pkg',
name: "pkg"
}
// CORRECT
{
"name": "pkg"
}Look for conflict markers:
// WRONG - contains merge markers
{
"name": "pkg",
<<<<<<< HEAD
"version": "1.0.0"
=======
"version": "2.0.0"
>>>>>>> branch
}Resolve conflicts and remove markers.
Use an editor with JSON validation (VS Code has built-in support). Enable format-on-save for JSON files. Consider using jsonc (JSON with comments) for config files that support it, but remember package.json must be strict JSON. For programmatic JSON generation, always use JSON.stringify() rather than string concatenation.