# gulp-json-editor

> A gulp plugin to edit JSON objects

Latest version **2.6.0** (published 2023-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-json-editor
pnpm add gulp-json-editor
yarn add gulp-json-editor
bun add gulp-json-editor
```

## Health

**Score 38/100 (D)** — status: abandoned.

Positive: has types package; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.6.0 |
| Published | 2023-12-17 |
| First published | 2014-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-json-editor) |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | gulp-community |
| Maintainers | phated, rejas |
| Keywords | gulpplugin, gulp, json |

## Links

- npm: https://www.npmjs.com/package/gulp-json-editor
- Repository: https://github.com/gulp-community/gulp-json-editor
- Homepage: https://github.com/gulp-community/gulp-json-editor#readme
- Issues: https://github.com/gulp-community/gulp-json-editor/issues
- npm.io page: https://npm.io/package/gulp-json-editor

## Dependencies (5)

- [through2](https://npm.io/package/through2.md) ^4.0.2
- [deepmerge](https://npm.io/package/deepmerge.md) ^4.3.1
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.14.11
- [plugin-error](https://npm.io/package/plugin-error.md) ^2.0.1
- [detect-indent](https://npm.io/package/detect-indent.md) ^6.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.6.0 (latest) — 2023-12-17
- 2.5.7 — 2023-07-14
- 2.5.6 — 2021-05-18
- 2.5.5 — 2021-04-06
- 2.5.4 — 2019-10-23
- 2.5.3 — 2019-07-23
- 2.5.2 — 2019-05-01
- 2.5.1 — 2019-03-01
- 2.5.0 — 2018-12-26
- 2.4.4 — 2018-12-05
- 2.4.3 — 2018-11-06
- 2.4.2 — 2018-07-24
- 2.4.1 — 2018-05-18
- 2.4.0 — 2018-05-18
- 2.3.0 — 2018-03-28
- … 14 more at https://npm.io/package/gulp-json-editor/versions

## README

# gulp-json-editor

[![npm version](https://badge.fury.io/js/gulp-json-editor.svg)](https://www.npmjs.com/package/gulp-json-editor)
[![Automated tests](https://github.com/gulp-community/gulp-json-editor/actions/workflows/run-tests.yml/badge.svg)](https://github.com/gulp-community/gulp-json-editor/actions/workflows/run-tests.yml)

gulp-json-editor is a [gulp](https://github.com/gulpjs/gulp) plugin to edit JSON objects.

## Usage
```javascript
var jeditor = require("gulp-json-editor");

/*
  edit JSON object by merging with user specific object
*/
gulp.src("./manifest.json")
  .pipe(jeditor({
    'version': '1.2.3'
  }))
  .pipe(gulp.dest("./dest"));

/*
  edit JSON object by using user specific function
*/
gulp.src("./manifest.json")
  .pipe(jeditor(function(json) {
    json.version = "1.2.3";
    return json; // must return JSON object.
  }))
  .pipe(gulp.dest("./dest"));

/*
  specify [js-beautify](https://github.com/beautify-web/js-beautify) option
*/
gulp.src("./manifest.json")
  .pipe(jeditor({
    'version': '1.2.3'
  },
  // the second argument is passed to js-beautify as its option
  {
    'indent_char': '\t',
    'indent_size': 1
  }))
  .pipe(gulp.dest("./dest"));

/*
  specify [deepmerge](https://github.com/TehShrike/deepmerge) option
*/
gulp.src("./manifest.json")
  .pipe(jeditor({ 
    "authors": ["tomcat"] 
  },
  // the second argument is passed to js-beautify as its option
  {},
  // the third argument is passed to deepmerge options, eg, arrayMerge options
  { 
    arrayMerge: function (dist,source,options) {return source;} 
  }))
  .pipe(gulp.dest("./dest"));
```

### Note
In case of such above situation, all of comment and whitespace in source file is **NOT** kept in destination file.

### Disable beautification

```javascript
gulp.src("./manifest.json")
  .pipe(jeditor({
    'version': '1.2.3'
  },
  {
    beautify: false
  }))
  .pipe(gulp.dest("./dest"));
```


## API
### jeditor(editorObject, [jsBeautifyOptions], [deepmergeOptions])
#### editorObject
Type: `JSON object`

JSON object to merge with.

#### jsBeautifyOptions
Type: `object`

This object is passed to js-beautify as its option.

#### deepmergeOptions
Type: `object`

This object is passed to deepmerge as its [option](https://github.com/TehShrike/deepmerge#options).

### jeditor(editorFunction, [jsBeautifyOptions], [deepmergeOptions])
#### editorFunction
Type: `function`

The `editorFunction` must have the following signature: `function (json) {}`, and must return JSON object or PromiseLike object with JSON object as value.

#### jsBeautifyOptions
Type: `object`

This object is passed to js-beautify as its option.

#### deepmergeOptions
Type: `object`

This object is passed to deepmerge as its [option](https://github.com/TehShrike/deepmerge#options).

## License

Copyright (c) 2023 gulp-community

Licensed under the [MIT license](LICENSE).

---
_Source: https://npm.io/package/gulp-json-editor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
