This takes about 4–8 seconds on my machine
npx has to first download the
If that's too slow for you,
install the package globally:
# i = install
# -g = --global
npm i -g sort-package-json
Then you can run just:
And it will take less than a second.
Of course you can also install the package locally and even run it in Git's pre-commit hook (using Husky or Lefthook) or in your CI pipeline. More options are mentioned in the package's documentation.
Source: My own Stack Overflow answer