New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-json-sort

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-json-sort

Gulp plugin for deterministic sorting of JSON files

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
901
decreased by-32.71%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 24 Jul 2015

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