config your json config by comand line
based on sindresorhus/conf
$ npm install zc-conf -g
# or use yarn
$ yarn global add zc-conf
Now, if we have a test.json like this:
{
"name": "zcong1993",
"age": 18
}
$ zc-conf test.json get
# we will get
{ name: 'zcong1993', age: 18 }
$ zc-conf test.json get name
# we will get
# zcong1993
if the file not exists,
zc-conf
will help you create first
$ zc-conf test.json set language javascript
$ less test.json
# we will find
{
"name": "zcong1993",
"age": 18,
"language": "javascript"
}
$ zc-conf test.json set user.name zcong1993
# less test.json
{
"name": "zcong1993",
"age": 18,
"language": "javascript",
"user": {
"name": "zcong1993"
}
}
$ zc-conf test.json set langiage php -f # or use --force
now we can change the attribute
if the key not exists ,this command is same as
set
, but the value isarray
$ zc-conf test.json add language php
$ less test.json
{
"name": "zcong1993",
"age": 18,
"language": [
"javascript",
"php"
]
}
$ zc-conf test.json has name
# true
$ zc-conf test.json has test
# false
$ zc-conf test.json delete user
{
"name": "zcong1993",
"age": 18,
"language": "javascript"
}
# if we clear test.json
$ zc-conf test.json clear
$ less test.json
# we will get
{}