glob-json
v0.0.2
Published
Edit JSON files from CLI with globbing patterns
Downloads
4
Readme
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 <dstPathGlob> [srcPath] <set|del|merge> <dstKeyGlob> [--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 <dstKeyGlob> [--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 <dstKeyGlob>
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 <dstKeyGlob> <srcKey>
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