Gulp plugin for deterministic sorting of JSON files
npm install gulp-json-sortjavascript
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
`typescript
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
});
``