https://github.com/iyegoroff/glob-json
Edit JSON files from CLI with globbing patterns
https://github.com/iyegoroff/glob-json
cli glob json
Last synced: 3 months ago
JSON representation
Edit JSON files from CLI with globbing patterns
- Host: GitHub
- URL: https://github.com/iyegoroff/glob-json
- Owner: iyegoroff
- License: mit
- Created: 2022-05-18T22:03:27.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-18T22:27:48.000Z (about 4 years ago)
- Last Synced: 2025-02-14T11:54:28.572Z (over 1 year ago)
- Topics: cli, glob, json
- Language: JavaScript
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# glob-json
[](https://npm.im/glob-json)
[](https://github.com/iyegoroff/glob-json/actions/workflows/build.yml)
[](https://github.com/iyegoroff/glob-json/actions/workflows/publish.yml)
[](https://codecov.io/gh/iyegoroff/glob-json)

[](https://www.npmjs.com/package/glob-json)
## Installation
```
npm i glob-json
```
## Description
Utility to modify JSON files with globbing patterns. It uses 'glob' and 'minimatch' in 'dot:true' mode. Since the '/' character is used as a path separator for keys, this tool has some limitations. For example, 'x/\*/z' key pattern will match '{ x: { y: { z: 1 } } }', but not '{ x: { "y/w": { z: 1 }}}'.
Usage:
`glob-json [srcPath] [--key|--number|--string|--true|--false|--null|srcKey] [value]`
Options:
dstPathGlob - a glob pattern to select destination files
srcPath - path to a source file, if not specified each destination file will be its own source
Commands:
`set [--string|--number|--true|--false|--null|--key] [value]`
Changes properties in destination files
Options:
dstKeyGlob - a glob pattern to select paths in destination files
-s, --string - treat next argument as a string value, this is the default option
-n, --number - treat next argument as a number value
-t, --true - set selected properties to 'true'
-f, --false - set selected properties to 'false'
--null - set selected properties to 'null'
-k, --key - treat next argument as a path to value in a source file
value - source value or a path to value in a source file
Examples:
glob-json 'fixtures/**/*.json' set version --number 5
glob-json package.json my-lib.json set 'dependencies/my-lib' --key version
`del `
Deletes properties from destination files
Options:
dstKeyGlob - a glob pattern to select paths in destination files
Examples:
glob-json temp.json del 'some/**/deeply/*/nested/key'
`merge `
Merges property from source file into destination files
Options:
dstKeyGlob - a glob pattern to select paths in destination files
srcKey - path to value in a source file
Examples:
glob-json 'packages/*/package.json' merge '' publishConfig