Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-json

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-json

Takes a json-file and return a copy of the same file, but sorted

  • 1.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
234K
increased by4.7%
Maintainers
1
Weekly downloads
 
Created

What is sort-json?

The sort-json npm package is a utility for sorting the keys of a JSON object. It helps in maintaining a consistent order of keys, which can be useful for readability, comparison, and version control.

What are sort-json's main functionalities?

Sort JSON keys alphabetically

This feature sorts the keys of a JSON object in alphabetical order. The code sample demonstrates how to use the sort-json package to sort an unsorted JSON object.

const sortJson = require('sort-json');
const unsortedJson = { "b": 2, "a": 1, "c": 3 };
const sortedJson = sortJson(unsortedJson);
console.log(sortedJson); // { "a": 1, "b": 2, "c": 3 }

Sort JSON keys with custom comparator

This feature allows sorting the keys of a JSON object using a custom comparator function. The code sample shows how to sort the keys in reverse alphabetical order.

const sortJson = require('sort-json');
const unsortedJson = { "b": 2, "a": 1, "c": 3 };
const sortedJson = sortJson(unsortedJson, { comparator: (a, b) => b.localeCompare(a) });
console.log(sortedJson); // { "c": 3, "b": 2, "a": 1 }

Sort nested JSON objects

This feature sorts the keys of nested JSON objects. The code sample demonstrates how to sort a JSON object with nested objects.

const sortJson = require('sort-json');
const unsortedJson = { "b": { "d": 4, "c": 3 }, "a": 1 };
const sortedJson = sortJson(unsortedJson, { depth: null });
console.log(sortedJson); // { "a": 1, "b": { "c": 3, "d": 4 } }

Other packages similar to sort-json

FAQs

Package last updated on 12 Jan 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc