Use physical JSON files as a key value store


001.1.24 years ago4 years agoMinified + gzip package size for @infracloud/jsonkvs in KB



Use physical JSON files as a key value store


const jsonkvs = require('jsonkvs')
const packageJson = jsonkvs('./myFile.json')

packageJson.set('one', 'some value')
packageJson.save() // write changes


Key Default Detail
tabSpace '\t' What character to use to indent output JSON. Defaults to hard tab.


jsonkvs(path, config)

Load a JSON file at a given path.


Get the value of a given key. If no key is passed will return the whole object.

.set(key, value | patch, replace=false)

Set the value of a given key. Can be called two ways:

  • By passing the key as first argument and value as second.
  • By passing an patch object. In this case the patch will be merged. If replace is set then the original file will be overridden by the patch


Unset a given keys


Commit changes to disk


  • When a file is open it's contents is loaded into memory and it's not locked.
  • If the file changes on the FS it's contents should be reread and memory copy updated.
  • Any pending changes in memory will superseed new changes from disk.
  • The above bollocks should all be configurable (you can lock a file, get/set directly from the file (via inmemory cache), conflict resolution)
  • Can save to an alternative location


(MIT 2-Clause)

Copyright (c) 2017, Infracloud Ltd All rights reserved.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.