package.json Builder

Generate a complete package.json for any Node.js project

Build a valid package.json with name, version, description, type, main, scripts, dependencies, devDependencies, engines, license, and repository fields — validated field names and copy-ready JSON output.

What format must the name field be in?

The name must be lowercase, URL-safe, and at most 214 characters. It may contain hyphens and may be scoped like @scope/name, but no spaces, uppercase letters, or leading dots or underscores. This builder normalizes obvious issues for you.

Build a valid package.json without guessing field names

Every Node.js project is anchored by a package.json — the manifest that declares its name, version, dependencies, and the scripts you run with npm run. A typo in a field name or an invalid version range silently breaks tooling. This builder collects the standard fields, validates the ones with strict rules (name casing, semver versions), and emits clean, indented JSON ready to drop into your project root.

How it works

The builder assembles a single JSON object from your inputs, only including fields you actually fill in so the output stays minimal. A few fields have rules the tool enforces:

  • name is lowercased and stripped of illegal characters; scoped names like @acme/widget are preserved.
  • version follows semantic versioning, MAJOR.MINOR.PATCH, defaulting to 1.0.0.
  • scripts, dependencies, and devDependencies become nested objects, for example:
{
  "scripts": { "build": "tsc", "test": "jest" },
  "dependencies": { "express": "^4.19.0" }
}

Dependency versions use npm range syntax: ^1.2.3 allows compatible minor and patch updates, ~1.2.3 allows only patch updates, and an exact 1.2.3 pins the version. The output is serialized with two-space indentation, the convention npm itself writes.

Tips and notes

  • Set private: true on applications so a stray npm publish cannot leak them to the public registry.
  • Keep your entry point (main) accurate; bundlers and require() resolution rely on it for packages consumed by others.
  • Use engines to document the Node version your CI runs, so contributors get a warning instead of cryptic runtime errors.
  • After saving, run npm install to generate the lockfile that pins the exact resolved versions of every dependency.