package.json Formatter & Key Sorter
Pretty-print a package.json and reorder its keys into the conventional npm order (name, version, description, ... dependencies, devDependencies, ...). Sorts dependencies, devDependencies, peerDependencies and similar maps alphabetically by package name, and preserves any non-standard fields at the end.
Input
Output
Guides
The package.json Formatter & Key Sorter cleans up a Node.js package.json file: it pretty-prints the JSON with consistent indentation and reorders the top-level keys into the order the npm ecosystem actually uses — name, version, description, and so on down to dependencies, devDependencies, and the rest. Paste a package.json that has been hand-edited, merged from a template, or generated by a scaffolding tool, and get back one that reads the way npm init and most style guides expect.
Everything runs locally in your browser — your manifest, including private package names, internal registry URLs, or scoped dependency names, is never uploaded anywhere.
How to use it
- Paste your
package.jsoncontents into the input box. - Pick an indent — 2 spaces (the npm default), 4 spaces, or tabs.
- The formatted result appears automatically as you type, ready to copy or download as
package.json.
What key order does it use?
Top-level fields are reordered into the conventional npm sequence: identity and metadata first (name, version, private, description, keywords, homepage, bugs, license, author, contributors, funding), then module-resolution fields (type, main, module, browser, exports, imports, types/typings, bin, man, files, directories, repository), then the fields most people actually scroll down to check (scripts, config, dependencies, devDependencies, peerDependencies, peerDependenciesMeta, optionalDependencies, bundledDependencies), and finally environment constraints and publishing metadata (engines, os, cpu, sideEffects, workspaces, publishConfig, packageManager).
Any field this tool doesn't recognize — a custom config block from a build tool, or anything else — is kept, not dropped, and placed after the standard fields in its original order relative to other unknown fields.
Are my dependencies sorted too?
Yes. Inside dependencies, devDependencies, peerDependencies, peerDependenciesMeta, optionalDependencies, and bundledDependencies, the individual package names are sorted alphabetically. This is the change you'll see most often in a diff — a dependency added at the end of a list by an editor or a quick npm install snaps back into alphabetical order, which is what most lint rules (like sort-package-json or ESLint's package-json plugins) expect and what makes merge conflicts in that section easier to resolve.
Other object-valued fields, such as scripts, keep their original order — reordering scripts can be meaningful (grouping build steps together), unlike a plain dependency list.
What if my JSON is invalid?
The tool checks that the input parses as valid JSON before doing anything else. If it doesn't — a trailing comma, an unquoted key, a missing brace — you'll get a specific parse error pointing at the problem instead of a blank or broken result. The same check applies if the JSON parses but isn't an object (for example, if you accidentally pasted an array).
Does this validate my package.json against npm's rules?
No — this is a formatter, not a linter. It doesn't check that name is a valid npm package name, that version is valid semver, or that dependency version ranges are well-formed. It only reorders and re-indents whatever valid JSON you give it.
Privacy
This tool runs entirely in your browser. Your package.json is never uploaded to a server, logged, or stored.