Validate a package.json File

A single misplaced comma, a trailing comma after the last property, or a stray single quote in package.json is enough to stop npm install, yarn, and pnpm dead in their tracks with error messages like "Unexpected token" that give you line numbers pointing to the wrong location. This example shows a realistic package.json for a Next.js project with scripts, dependencies, and devDependencies — the three sections every JavaScript project has. Developers most commonly encounter malformed package.json after manually editing it to add a dependency, after resolving a git merge conflict that left duplicate or mismatched braces, or after copy-pasting a script from documentation that used smart quotes instead of straight double quotes. The validator catches all these cases instantly, showing you the exact line and column of the first syntax error. Key parts of this example: the name and version fields at the top are required for packages published to npm. The scripts block maps short command names to longer commands, so npm run dev executes next dev. The dependencies block contains runtime packages while devDependencies contains tools only needed during development, keeping your production bundle lean. Real-world scenarios: a CI pipeline fails on the very first step because package.json was edited on Windows and saved with a byte-order mark (BOM) that corrupts the first character; a developer adds a comment above a dependency (forgetting JSON doesn't allow comments) and breaks the build for the whole team; a merge conflict leaves both branches' dependency versions separated by conflict markers instead of a comma. Tips and pitfalls: JSON requires double quotes — single quotes are invalid. Trailing commas after the last item in an object or array are not allowed in standard JSON (though they're allowed in JSONC used by some tools). Keys must also be strings in double quotes, not bare identifiers. To customise: paste your actual package.json here to verify syntax before running installs. The validator works equally well for package.json files in npm, yarn, and pnpm projects.

Example
{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "lint": "eslint ."
  },
  "dependencies": {
    "next": "14.2.0",
    "react": "18.3.0"
  },
  "devDependencies": {
    "typescript": "5.4.0"
  }
}
[ open in JSON Validator → ]

FAQ

What breaks package.json syntax?
The most common mistakes are trailing commas after the last property, single-quoted strings instead of double quotes, and missing commas between entries.
Does this validate npm field requirements?
This tool validates JSON syntax. For npm-specific field validation (required name, valid semver versions) you still need to run npm itself.
Can I use this for yarn or pnpm?
Yes. yarn and pnpm both use package.json with the same JSON syntax, so this validator works for all three package managers.

Related Examples