https://github.com/kikobeats/jsonsort
Sort an array of objects based on a criteria
https://github.com/kikobeats/jsonsort
cli criteria json sort
Last synced: 4 months ago
JSON representation
Sort an array of objects based on a criteria
- Host: GitHub
- URL: https://github.com/kikobeats/jsonsort
- Owner: Kikobeats
- License: mit
- Created: 2019-02-19T14:02:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-07T08:00:30.000Z (8 months ago)
- Last Synced: 2024-10-17T17:56:37.299Z (6 months ago)
- Topics: cli, criteria, json, sort
- Language: JavaScript
- Homepage: https://nicedoc.io/Kikobeats/jsonsort
- Size: 72.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @kikobeats/jsonsort

[](https://travis-ci.org/Kikobeats/jsonsort)
[](https://www.npmjs.org/package/@kikobeats/jsonsort)> Sort an object or a collection of objects based on a criteria.
## Install
```bash
$ npm install @kikobeats/jsonsort --global
```## CLI
```bash
$ jsonsort [flags]Flags
--criteria Specify the criteria to sort. It can be a key name or fat arrow function.
--quiet Avoid print output
--save Write the output back. If a path is specified, it will be used over the originalExamples
$ jsonsort file.json # Just output a sorted json
$ jsonsort file.json --criteria name # Sort an array of objects based on alphabetical `name` value.
$ jsonsort file.json --criteria 'x => x.featured' # Passing a function as criteria.
$ jsonsort file.json --criteria name --save # Sort and save the result.
$ jsonsort file.json --criteria name --save # Sort, save but dont print result.```
It's easy to complement with others UNIX commands, like `jq`:
```bash
jq .redirects now.json | jsonsort --criteria source
```## License
**jsonsort** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/jsonsort/blob/master/LICENSE.md) License.
Authored and maintained by Kiko Beats with help from [contributors](https://github.com/Kikobeats/jsonsort/contributors).> [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · Twitter [@Kikobeats](https://twitter.com/Kikobeats)