Registry / devops / prettier-plugin-sort-json

prettier-plugin-sort-json

JSON →
library4.2.0jsnpmunverified

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.

npm install prettier-plugin-sort-json
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SO
P
prettier-plugin-sort-json
devopsjavascriptv4.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
import prettierPluginSortJson from 'prettier-plugin-sort-json'
const prettierPluginSortJson = require('prettier-plugin-sort-json')
Default import; ESM-only since v3 (Prettier v3 support)
SortJsonOptions
import type { SortJsonOptions } from 'prettier-plugin-sort-json'
import { SortJsonOptions } from 'prettier-plugin-sort-json'
TypeScript type, can be imported as type to avoid bundling
CategorySort
import { CategorySort } from 'prettier-plugin-sort-json'
import CategorySort from 'prettier-plugin-sort-json'
Named export for configuring category sort order

Shows how to configure Prettier with the plugin and a custom sort order, sorting 'name' and 'version' keys alphabetically and leaving others unsorted.

// .prettierrc.js module.exports = { plugins: ['prettier-plugin-sort-json'], jsonSortOrder: '{"name": "alphabetical", "version": "alphabetical", "*": "none"}', }; // Or use with CLI // prettier --write "**/*.json" --plugin prettier-plugin-sort-json
Debug
Known issues
breakingDrop support for Node.js v16 in v4.0.0
fix
Upgrade to Node.js >=18.0.0
affects: >=4.0.0
breakingUpdated case insensitive sort to use deterministic key order in v4.0.0
fix
Review JSON files that relied on original order for case-insensitive sorts; keys with same case may now be sorted differently
affects: >=4.0.0
breakingMigration to Prettier v3 in v3.0.0 (plugin no longer auto-loaded)
fix
Explicitly add plugin to prettier configuration (e.g., `plugins: ['prettier-plugin-sort-json']`)
affects: >=3.0.0
breakingChanged `jsonSortOrder` option from file path to JSON string in v1.0.0
fix
Update configuration to use JSON string instead of path (e.g., {"name": "alphabetical"})
affects: >=1.0.0
deprecatedPrettier v2 support removed in v3.0.0; use v2.x of this plugin for Prettier v2
fix
Downgrade to prettier-plugin-sort-json@2 for Prettier v2, or upgrade to Prettier v3
affects: >=3.0.0
gotchajsonSortOrder validation error if not set (fixed in v4.1.1)
fix
Set jsonSortOrder in prettier config or upgrade to v4.1.1+
affects: >=4.0.0 <4.1.1
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-sort-json'
Prettier v3 no longer auto-loads plugins; plugin not in config
fix
Add `plugins: ['prettier-plugin-sort-json']` to your Prettier config (e.g., .prettierrc.js)
Error: jsonSortOrder must be a JSON string
Using a file path instead of JSON string for jsonSortOrder option
fix
Replace the file path with a JSON string like `{"name": "alphabetical"}`
Error: Invalid sort order
jsonSortOrder contains invalid sort algorithm name or mismatched brackets
fix
Ensure jsonSortOrder is valid JSON and uses allowed sort options: alphabetically, natural, caseInsensitive, caseSensitive, none
TypeError: prettier-plugin-sort-json is not a function
Incorrect import syntax in CJS project
fix
Use `import` or in CJS: `const plugin = require('prettier-plugin-sort-json').default`
Upgrade
Version history
4.2.0latest on npm
Audit
Dependencies
prettierrequiredPeer dependency required to function as a plugin
Agent activity
6 hits · last 30 days
node
6
Resources
prettier-plugin-sort-json — npm install prettier-plugin-sort-json · libregistry