json-chain
fluent chaining for json with dot-prop access
usage
yarn add json-chain
npm i json-chain --save
const JSONChain = require('json-chain')
examples
const data = {
eh: ['og'],
canada: true,
}
const chain = JSONChain.init(data).update('eh', ['some values'])
reading json file
const {readFileSync} = require('fs')
const pkg = readFileSync('./package.json', 'utf8')
const chain = new JSONChain(pkg)
.parse() // will be done automatically, is optional
.set('eh', ['some values']) // also as .update
.del('eh') // also as .delete, .remove
// also as .val
const test = chain.get('scripts.test')
const has = chain.has('version')
writing to file
- has
.toStringand.toJSONmethods for auto-stringifying when cast tostringorJSON.stringify
keep it simple
const chain = new JSONChain(pkg)
.updateIfNotEmpty('scripts.test', 'ava --verbose')
.updateIfNotEmpty('scripts.devDependencies', {'ava': '*'})
.write()