How to fix Error: Unexpected token } in JSON at position 123 (malformed package.json) in Node.js
This error occurs when Node.js tries to parse your package.json file but finds invalid JSON syntax. Common culprits include missing commas, mismatched quotes, or trailing commas. The error can be fixed by validating the JSON structure and correcting syntax errors.
Quick fix
Fixes Error: Unexpected token } in JSON at position 123 (malformed package.json)
{
"name": "my-app",
"version": "1.0.0"
}- Validate JSON syntax using an online tool
- Check for common JSON mistakes
- Edit the file in a code editor with JSON support
- Check file encoding if the error persists
{"name": "my-app","version": "1.0.0"}Error: Unexpected token } in JSON at position 123 (malformed package.json)
What this error means
When Node.js or npm starts, it reads and parses the package.json file to understand your project configuration. If the JSON syntax is invalid—such as missing commas between properties, unquoted keys, or extra closing braces—the JSON parser throws an error at the position where it encounters the problem. The position number (like 123) tells you roughly where in the file the syntax error occurs. This prevents npm from reading your dependencies and prevents your Node.js application from starting. The "Unexpected token" error means the parser found a character it didn't expect at that specific position in the file. Unlike JavaScript, JSON has strict syntax rules: all property names must be in double quotes, no trailing commas are allowed, and no comments are permitted.
Typical symptoms
- npm install fails with "Unexpected token" error
- npm start or npm run commands fail immediately
- Node.js application won't start
- Error mentions "JSON at position" with a number
- npm list or npm view commands throw parsing errors
Common causes
- Missing comma between object properties in package.json
- Trailing comma after the last property in an object or array
- Unquoted property names (property keys must be in double quotes)
- Single quotes used instead of double quotes
- Mismatched or missing closing braces/brackets
- File encoding issues (file saved as UTF-16 or with BOM instead of UTF-8)
- Accidental deletion or corruption of JSON structure
How to fix "Error: Unexpected token } in JSON at position 123 (malformed package.json)"
Copy the contents of your package.json and paste it into a JSON validator like JSONLint (jsonlint.com) or the built-in validator in VS Code. The validator will pinpoint the exact line and character where the syntax error occurs.
Review your package.json for these common errors:
1. Missing commas: Each property except the last must be followed by a comma
{
"name": "my-app",
"version": "1.0.0"
}2. Trailing commas: Remove commas after the last property
{
"name": "my-app",
"version": "1.0.0" // No comma here
}3. Use double quotes: JSON requires double quotes, not single quotes
{
"name": "my-app" // Correct
'name': 'my-app' // Wrong
}Open package.json in VS Code, Sublime Text, or a similar editor. Most modern editors highlight JSON syntax errors in red. The error tooltip will help you identify the problem. Fix the syntax error and save the file.
If the file looks corrupted with strange symbols, the file may have been saved with incorrect encoding. Right-click the file > Properties (Windows) or Get Info (macOS), then ensure it's saved as UTF-8 without BOM. In VS Code, click the encoding indicator ("UTF-8") in the bottom right and select "Reopen with Encoding > UTF-8".
If you have the file in git, revert to the last known good version:
git checkout HEAD -- package.jsonOr restore from a backup if version control is not available.
Once package.json is corrected, clear the npm cache and reinstall dependencies:
npm cache clean --force
npm installAdvanced notes
For large projects or automated validation, use the package-json-validator npm package to programmatically validate package.json structure. This ensures your package.json conforms to npm's schema before attempting to parse it. Additionally, if working with monorepos or complex dependency trees, consider using npm lint or third-party tools like publint to validate the entire structure. When managing package.json programmatically, always use JSON serialization libraries that produce valid JSON (e.g., JSON.stringify() in Node.js) rather than string concatenation to avoid syntax errors.
Frequently asked questions
- What does "Error: Unexpected token } in JSON at position 123 (malformed package.j" mean?
- json file to understand your project configuration. If the JSON syntax is invalid—such as missing commas between properties, unquoted keys, or extra closing braces—the JSON parser throws an error at the position where it encounters the problem. The position number (like 123) tells you roughly where in the file the syntax error occurs.
- How do I fix "Error: Unexpected token } in JSON at position 123 (malformed package.j"?
- This error occurs when Node.js tries to parse your package.json file but finds invalid JSON syntax. Common culprits include missing commas, mismatched quotes, or trailing commas. The error can be fixed by validating the JSON structure and correcting syntax errors.
- What causes "Error: Unexpected token } in JSON at position 123 (malformed package.j"?
- Missing comma between object properties in package.json Trailing comma after the last property in an object or array Unquoted property names (property keys must be in double quotes)
- Is the "Error: Unexpected token } in JSON at position 123 (malformed package.j" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚Node.js Official Documentation
- 📖npm Docs: package.json configuration reference(Official Docs)
- 📖npm Docs: Common errors guide(Official Docs)
- 🐙
- 📝