Don't like ads? Go Ad-Free Today

Package.json Formatter & Key Sorter

DataDeveloper
ADVERTISEMENT · REMOVE?
Validation and recommendations will appear here.
ADVERTISEMENT · REMOVE?

Guide

Package.json Formatter & Key Sorter

Package.json Formatter & Key Sorter

Paste any package.json to get a clean, canonical-ordered version back instantly. This tool reorders top-level keys to the standard npm sequence (name, version, description, scripts, dependencies, and so on), validates required and recommended fields, checks your dependency version ranges, and flags non-standard keys that clutter the manifest. Everything happens in your browser — nothing is uploaded.

How to Use

  1. Paste your package.json into the input area (or click “Try an example” to see the tool in action).
  2. Pick your preferred indent style: 2 spaces, 4 spaces, or tab.
  3. Optionally enable alphabetical sorting for dependency groups and lifecycle-aware sorting for scripts.
  4. Toggle “Strip non-standard fields” if you want to drop unknown top-level keys.
  5. Review the formatted output on the right plus the validation report with errors, warnings, and notes.
  6. Copy the result or download it directly as package.json.

Features

  • Canonical key ordering – Top-level fields reordered to the standard npm sequence so diffs and code reviews stay consistent.
  • Required and recommended field checks – Flags missing name/version and recommended entries like description, license, and repository.
  • Version range validation – Verifies each entry in dependencies, devDependencies, peerDependencies, and optionalDependencies uses a valid semver range (caret, tilde, ranges, workspace protocols, and more).
  • Dependency sorting – Optionally alphabetise every dependency group for predictable lockfile-friendly output.
  • Lifecycle-aware script sorting – Keeps preX/X/postX npm lifecycle scripts grouped together, then sorts the rest alphabetically.
  • Strip non-standard fields – Remove unknown top-level keys to keep your manifest lean, or keep them (they are moved to the bottom).
  • Indent control – Output with 2 spaces, 4 spaces, or a tab character to match your project’s formatting rules.
  • Client-side only – Parsing, validation, and reordering run entirely in your browser. Nothing is transmitted.

FAQ

  1. Why does the order of keys in package.json matter?

    The JSON specification treats objects as unordered, but in practice key order affects human readability, diff clarity in pull requests, and how various tools present the file. A canonical order — popularised by the npm CLI and widely adopted by ecosystem tools — places identity fields (name, version) first, followed by metadata, entry points, and finally dependency and configuration blocks. Consistent ordering reduces merge conflicts and makes manifests easier to scan.

  2. What is semver and why does version range syntax matter?

    Semantic Versioning (semver) defines versions as MAJOR.MINOR.PATCH triples with strict rules about what each segment signals. Range operators like caret (^), tilde (~), and comparators (>=, <) tell package managers which future versions you are willing to accept without breaking your contract. An invalid or ambiguous range can cause reproducible-build failures or unexpected upgrades. Validating ranges up-front catches typos before they reach a lockfile.

  3. What counts as a non-standard field in package.json?

    The npm manifest spec defines a fixed vocabulary of top-level fields with documented meaning (name, version, scripts, dependencies, engines, and so on). Tools frequently add their own top-level keys — ESLint configuration, Husky hooks, build tool settings. These are technically valid JSON but live outside the npm spec. Some projects prefer to keep them for convenience, others move them to dedicated config files to keep the manifest focused on packaging concerns.

  4. Why group npm lifecycle scripts instead of just sorting alphabetically?

    npm runs lifecycle scripts in a defined order: preinstall before install, prepublish before publish, and so on. When you read a scripts block, grouping related lifecycle trios (pre/main/post) together makes the execution flow obvious at a glance. Pure alphabetical sorting would scatter these pairs — for example, placing 'postbuild' far from 'build' — making it harder to reason about what runs when.

Want To enjoy an ad-free experience? Go Ad-Free Today

Install Our Extensions

Add IO tools to your favorite browser for instant access and faster searching

Add to Chrome Extension Add to Edge Extension Add to Firefox Extension Add to Opera Extension

Scoreboard Has Arrived!

Scoreboard is a fun way to keep track of your games, all data is stored in your browser. More features are coming soon!

ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?

News Corner w/ Tech Highlights

Get Involved

Help us continue providing valuable free tools

Buy me a coffee
ADVERTISEMENT · REMOVE?