Skip to content

About

Modify a value on a JSON path

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

gulp-json-modify

CI npm version

Modify a value in a JSON file using gulp

Install

Requires Node.js 20 or later.

npm install --save-dev gulp-json-modify

Usage

const { src, dest } = require('gulp')
const jsonModify = require('gulp-json-modify')

function setVersion() {
  return src(['./bower.json', './package.json'])
    .pipe(jsonModify({
      key: 'version',
      value: '1.0.0'
    }))
    .pipe(dest('./'))
}

exports.default = setVersion

Options

key

Type: string (required)

The key to set. Use dot notation to set nested keys:

.pipe(jsonModify({ key: 'key.subkey', value: 'set-me-to' }))

/*
{
  "key": {
    "subkey": "set-me-to"
  }
}
*/

Missing intermediate objects are created.

value

Type: any JSON-serialisable value (required)

The value to set. Falsy values such as false, 0 and '' are allowed; only undefined is rejected.

indent

Type: number | string

The indentation passed to JSON.stringify. By default, the plugin detects the indentation already used in the file (tabs or spaces) and keeps it. A trailing newline is also kept if the file had one.

Releasing

Releases are published to npm by GitHub Actions (publish.yml) using npm trusted publishing.

Create a GitHub Release with a new vX.Y.Z tag (e.g. v2.1.0). Publishing the release triggers the npm publish.

The workflow sets the package.json version from the release tag before publishing, so there is no need to bump the version by hand. Tags that are not exactly vX.Y.Z fail the workflow.

Credits

Based on gulp-bump.

License

(MIT License)

Copyright (c) 2015 Steve Lacy me@slacy.me slacy.me

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Modify a value on a JSON path

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages