{"id":20425,"library":"prettier-plugin-sort-json","title":"Prettier Plugin Sort JSON","description":"A Prettier plugin that sorts JSON files alphanumerically by key. Version 4.2.0, actively maintained with regular releases. It supports custom sort orders, case-insensitive sorting, numeric sorting, and category-based sorting. Differentiators include deterministic key order for case-insensitive sorts, support for Prettier v3 (ESM), and TypeScript types. Requires Node.js >=18 and Prettier ^3.0.0.","status":"active","version":"4.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/Gudahtt/prettier-plugin-sort-json","tags":["javascript","typescript"],"install":[{"cmd":"npm install prettier-plugin-sort-json","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sort-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sort-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required to function as a plugin","package":"prettier","optional":false}],"imports":[{"note":"Default import; ESM-only since v3 (Prettier v3 support)","wrong":"const prettierPluginSortJson = require('prettier-plugin-sort-json')","symbol":"plugin","correct":"import prettierPluginSortJson from 'prettier-plugin-sort-json'"},{"note":"TypeScript type, can be imported as type to avoid bundling","wrong":"import { SortJsonOptions } from 'prettier-plugin-sort-json'","symbol":"SortJsonOptions","correct":"import type { SortJsonOptions } from 'prettier-plugin-sort-json'"},{"note":"Named export for configuring category sort order","wrong":"import CategorySort from 'prettier-plugin-sort-json'","symbol":"CategorySort","correct":"import { CategorySort } from 'prettier-plugin-sort-json'"}],"quickstart":{"code":"// .prettierrc.js\nmodule.exports = {\n  plugins: ['prettier-plugin-sort-json'],\n  jsonSortOrder: '{\"name\": \"alphabetical\", \"version\": \"alphabetical\", \"*\": \"none\"}',\n};\n\n// Or use with CLI\n// prettier --write \"**/*.json\" --plugin prettier-plugin-sort-json","lang":"javascript","description":"Shows how to configure Prettier with the plugin and a custom sort order, sorting 'name' and 'version' keys alphabetically and leaving others unsorted."},"warnings":[{"fix":"Upgrade to Node.js >=18.0.0","message":"Drop support for Node.js v16 in v4.0.0","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Review JSON files that relied on original order for case-insensitive sorts; keys with same case may now be sorted differently","message":"Updated case insensitive sort to use deterministic key order in v4.0.0","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Explicitly add plugin to prettier configuration (e.g., `plugins: ['prettier-plugin-sort-json']`)","message":"Migration to Prettier v3 in v3.0.0 (plugin no longer auto-loaded)","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update configuration to use JSON string instead of path (e.g., {\"name\": \"alphabetical\"})","message":"Changed `jsonSortOrder` option from file path to JSON string in v1.0.0","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Downgrade to prettier-plugin-sort-json@2 for Prettier v2, or upgrade to Prettier v3","message":"Prettier v2 support removed in v3.0.0; use v2.x of this plugin for Prettier v2","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Set jsonSortOrder in prettier config or upgrade to v4.1.1+","message":"jsonSortOrder validation error if not set (fixed in v4.1.1)","severity":"gotcha","affected_versions":">=4.0.0 <4.1.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add `plugins: ['prettier-plugin-sort-json']` to your Prettier config (e.g., .prettierrc.js)","cause":"Prettier v3 no longer auto-loads plugins; plugin not in config","error":"Cannot find module 'prettier-plugin-sort-json'"},{"fix":"Replace the file path with a JSON string like `{\"name\": \"alphabetical\"}`","cause":"Using a file path instead of JSON string for jsonSortOrder option","error":"Error: jsonSortOrder must be a JSON string"},{"fix":"Ensure jsonSortOrder is valid JSON and uses allowed sort options: alphabetically, natural, caseInsensitive, caseSensitive, none","cause":"jsonSortOrder contains invalid sort algorithm name or mismatched brackets","error":"Error: Invalid sort order"},{"fix":"Use `import` or in CJS: `const plugin = require('prettier-plugin-sort-json').default`","cause":"Incorrect import syntax in CJS project","error":"TypeError: prettier-plugin-sort-json is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}