
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
sort-json-keys
Advanced tools
Sort JSON keys alphabetically at all levels (for example for sorting package-lock.json
).
Requires node@14
or higher:
npm install sort-json-keys --save-dev
Sort all keys in the foo.json
file in alphabetical order, indented by two spaces (default indentation):
npx sort-json-keys foo.json
Sorting the keys does not change the JS value of the JSON. In particular, array elements are not sorted.
For example this converts a JSON-file
{ "b": 1, "a": { "y": 2, "x": 3 }, "c": ["b", "a"] }
to a file
{
"a": {
"x": 3,
"y": 2
},
"b": 1,
"c": [
"b",
"a"
]
}
Sort all keys in foo.json
and baz/bar.json
files in alphabetical order, indented by two spaces:
npx sort-json-keys foo.json baz/bar.json
Sort all keys in foo.json
and bar.json
files, indented by four spaces:
npx sort-json-keys foo.json bar.json --indent 4
Sort all keys in foo.json
files without indentation (as a one-line file):
npx sort-json-keys foo.json --indent 0
import sortJsonKeys from "sort-json-keys";
// or
import { sortJsonKeys } from "sort-json-keys";
const json = { b: 1, a: 2 };
const sortedJson = sortJsonKeys(json); // { a: 2, b: 1 }
FAQs
Sort JSON keys alphabetically at all levels
The npm package sort-json-keys receives a total of 238 weekly downloads. As such, sort-json-keys popularity was classified as not popular.
We found that sort-json-keys demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.