How to fix npm ERR! code EJSONPARSE in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025ยท 151 views

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.

Quick fix

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 234
  1. Locate the error
  2. Validate JSON syntax
  3. Check for trailing commas
  4. Check for comments
npm โ€” error
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234
npm ERR! code EJSONPARSE

What this error means

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.

Typical symptoms

  • npm commands fail immediately with JSON parse error
  • Error points to specific line and column
  • Recently edited package.json
  • Merge conflict markers in JSON files
  • Copy-pasted JSON with hidden characters
  • Comments added to JSON file

Common causes

  1. Trailing comma after last item
  2. Missing comma between items
  3. Missing or extra brackets/braces
  4. Single quotes instead of double quotes
  5. Unquoted property names
  6. Comments in JSON (not allowed)
  7. Merge conflict markers
  8. BOM or hidden characters

How to fix "npm ERR! code EJSONPARSE"

1Locate the error

Read the error message carefully:

bash
npm install
# Output shows:
# npm ERR! JSON.parse Failed to parse json
# npm ERR! JSON.parse Unexpected token } in JSON at position 234

The position helps locate the error.

2Validate JSON syntax

Use a JSON validator:

bash
# Using jq
jq . package.json

# Using Node.js
node -e "require('./package.json')"

# Or use online validators like jsonlint.com
3Check for trailing commas

JSON doesn't allow trailing commas:

json
// WRONG
{
  "name": "pkg",
  "version": "1.0.0",  // <-- trailing comma ERROR
}

// CORRECT
{
  "name": "pkg",
  "version": "1.0.0"
}
4Check for comments

JSON doesn't support comments:

json
// WRONG
{
  // This is a comment - NOT ALLOWED
  "name": "pkg"
}

// CORRECT - no comments
{
  "name": "pkg"
}
5Use double quotes

JSON requires double quotes:

json
// WRONG
{
  'name': 'pkg',
  name: "pkg"
}

// CORRECT
{
  "name": "pkg"
}
6Check for merge conflicts

Look for conflict markers:

json
// WRONG - contains merge markers
{
  "name": "pkg",
<<<<<<< HEAD
  "version": "1.0.0"
=======
  "version": "2.0.0"
>>>>>>> branch
}

Resolve conflicts and remove markers.

Advanced notes

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.

Frequently asked questions

What does "npm ERR! code EJSONPARSE" mean?
json. JSON has strict syntax requirements - even small errors like a trailing comma, missing quote, or extra bracket will cause parsing to fail. npmrc, or any other JSON file that npm tries to read during its operation.
How do I fix "npm ERR! code EJSONPARSE"?
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.
What causes "npm ERR! code EJSONPARSE"?
Trailing comma after last item Missing comma between items Missing or extra brackets/braces
Is the "npm ERR! code EJSONPARSE" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading