Socket
Socket
Sign inDemoInstall

gulp-json-sort

Package Overview
Dependencies
71
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gulp-json-sort

Gulp plugin for deterministic sorting of JSON files


Version published
Maintainers
1
Install size
1.03 MB
Created

Readme

Source

gulp-json-sort NPM version Build Status

Gulp plugin for deterministic sorting of JSON files. Supports deep structures, custom compare functions, replacers, and formatting options.

Thin wrapper over substack's json-stable-stringify, which does all the hard work.

Usage

This plugin is authored in ES6, so until Node picks up ES6 module support you'll need to pluck the default property from the require'd import.

var gulp = require('gulp');
var sortJSON = require('gulp-json-sort').default;

gulp.task('sort-json', function() {
    return gulp.src('./**/*.json')
        .pipe(sortJSON({ space: 2 }))
        .pipe(gulp.dest('./'));
});

By default (with no compare function provided), sorting happens alphabetically by key.

If a file contains invalid JSON, a parse error will be emitted on the stream.

Newlines in the output are always LF. Pipe the results through gulp-eol as needed.

API

sortJSON(options?: {
    cmp?: (left: { key: string, value: any }, right: { key: string, value: any }) => number,
    cycles?: boolean,
    replacer?: (key: string, value: any) => any,
    space?: number | string
}); 

See json-stable-stringify for details and behavior for each option; the params are passed straight through.

License

MIT License (Expat)

Keywords

FAQs

Last updated on 24 Jul 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc