GithubHelp home page GithubHelp logo

fllstx / sort-json Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kesla/sort-json

0.0 0.0 0.0 184 KB

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

License: MIT License

JavaScript 100.00%

sort-json's Introduction

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

sort-json's People

Contributors

kesla avatar danielyaa5 avatar oprogramador avatar cschuller avatar revolunet avatar simounet avatar khaledmohamedp avatar w4andy avatar ffflorian avatar m-abs avatar pierrickp avatar vsa avatar dependabot[bot] avatar genru avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.