prettier-plugin-json-sort

raw JSON →
0.0.2 verified Sat Apr 25 auth: no javascript

A Prettier plugin that automatically sorts the keys in package.json and tsconfig.json files. At version 0.0.2, it is in early development with a single feature: sorting top-level keys in JSON configuration files. Unlike other sorting plugins (e.g., prettier-plugin-pkg), it focuses specifically on two JSON schemas. It ships TypeScript types and requires Prettier >= 2.0.0 as a peer dependency. Release cadence is irregular, and breaking changes are possible at this early stage.

error Cannot find module 'prettier-plugin-json-sort'
cause The plugin is not installed or not in node_modules.
fix
npm install prettier-plugin-json-sort --save-dev
error Error: Cannot find plugin 'prettier-plugin-json-sort' in plugins list
cause Prettier cannot locate the plugin module, possibly due to a misconfiguration in prettier.config.js or run from a different directory.
fix
Ensure plugins array includes the package name as a string (e.g., plugins: ['prettier-plugin-json-sort']). Run prettier from the project root where the plugin is installed.
error Error: Unsupported file type
cause Prettier tries to process a file that is not package.json or tsconfig.json with this plugin, which only supports those two types.
fix
Only run prettier --write on package.json or tsconfig.json, or configure the plugin to target those files specifically via file matching.
breaking The plugin may sort JSON keys in ways that break tools expecting a specific order (e.g., some parsers).
fix Review the sorted output and ensure compatibility with your toolchain. Consider using a more conservative sort or a selective configuration.
gotcha Only top-level keys are sorted – nested keys are not affected.
fix If you need nested key sorting, you must manually sort or use another plugin.
gotcha The plugin only sorts package.json and tsconfig.json by default – other JSON files are ignored.
fix If you want to sort other JSON files, consider using a more general JSON sorting plugin or a custom Prettier parser.
deprecated Version 0.0.2 is very early; future versions may change sorting behavior or introduce breaking changes without major version bump.
fix Pin the exact version in your package.json if stability is critical. Watch the repository for updates.
npm install prettier-plugin-json-sort
yarn add prettier-plugin-json-sort
pnpm add prettier-plugin-json-sort

Configures Prettier to use the plugin; then runs Prettier on package.json and tsconfig.json to sort keys.

// prettier.config.mjs
export default {
  plugins: ['prettier-plugin-json-sort'],
  // The plugin sorts package.json and tsconfig.json by default.
  // There are no additional options yet.
};

// In your terminal:
// npx prettier --write package.json tsconfig.json