A Prettier plugin that automatically sorts the keys of package.json files using sort-package-json. The current stable version is 3.0.2, released March 2026. It releases frequently (multiple versions per month) and only supports Prettier v3+ (dropped v2 support in v3.0.0). Key differentiators: provides a customizable sort order via the `packageSortOrder` option, ships TypeScript type declarations, and integrates seamlessly with Prettier's plugin system.
npm install prettier-plugin-packagejsonVerified import paths — ran on the pinned version, not inferred.
Install the plugin, configure with custom sort order, and format package.json.
Upgrade to Prettier v3 or pin to prettier-plugin-packagejson@2.x
Use `packageSortOrder` in config; see v2.5.0 changelog
Explicitly set `plugins: ['prettier-plugin-packagejson']` in .prettierrc, .prettierrc.js, or prettier.config.js
Ensure package.json is valid JSON; use JSON5 or similar if trailing commas needed, but plugin expects strict JSON
Test custom `packageSortOrder` on a sample file; if a field is not in the array, it will be placed after sorted ones in an undefined order
Install as a dev dependency: `npm i -D prettier-plugin-packagejson` and ensure `plugins: ['prettier-plugin-packagejson']` in config
Run `npm install`; check that the package is in `devDependencies`; use full path: `plugins: ['./node_modules/prettier-plugin-packagejson']` if needed
Rename option from `sortOrder` to `packageSortOrder` in Prettier config
Upgrade Prettier to v3: `npm i -D prettier@latest` or downgrade plugin: `npm i -D prettier-plugin-packagejson@2`