1. sort-json
Takes a json-file and return a copy of the same file, but sorted
sort-json
Package: sort-json
Created by: kesla
Last modified: Sun, 26 Jun 2022 22:16:30 GMT
Version: 2.0.1
License: MIT
Downloads: 834,169
Repository: https://github.com/kesla/sort-json

Install

npm install sort-json
yarn add sort-json

sort-json Build Status

It takes a JSON file and returns a copy of the same file, but with the sorted keys.

Installation

[sudo] npm -g install sort-json

Usage

 const sortJson = require('sort-json');

const options = { ignoreCase: true, reverse: true, depth: 1};
const copy = sortJson({ AA: 123, a: 1, b: 21 }, options);
// copy => { b: 21, AA: 123, a: 1 }

sortJson.overwrite('some/absolute/path.json', options);
// sorts the json at absolute path and overwrites file, also returns sorted object

sortJson.overwrite(['some/absolute/path1.json', 'some/absolute/path2.json'], options);
// sorts the json at absolute paths and overwrites files, also returns array of sorted objects

CLI usage

sort-json filename [options]
Sorts and overwrites .json or .rc files.

Example
sort-json test.json --ignore-case

Options

--ignore-case, -i
Ignore case when sorting.

--reverse, -r
Reverse the ordering z -> a

--depth=DEPTH, -d
The sorting DEPTH on multidimensional objects.
Use a number greater then 0 for the DEPTH value.

--indent-size=SIZE, --spaces=SIZE
Formats the file content with an indentation of SIZE spaces (default: detects the used indentation of the file).
Use a number greater then 0 for the SIZE value.

--no-final-newline, -nn
No final new line will be added to the end of the file.

Upgrade to version 2.x

sort-json 2.0.0 will create a different output when the source JSON file does not use an indent size of 2 spaces.
Use --indent-size=2 to always create an output file with 2 spaces.

Tests

npm test

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin