json-file
A Node.js module for reading/modifying/writing JSON files.
Install
$ npm install json-file
Usage
var json = ; // Load a JSON filevar file = json; // Read and write some valuesfile; // eg. "1.0.0"file; // eg. "git"file; // The raw dataconsole; // Write the updates to the filefile;
API
json.read ( String filePath[, Function callback ])
A shortcut for creating a json.File
object and loading the file contents.
// This...var file = json; // Is equivilent to this...var file = '/a/b/c';file; // Likewise, this...var file = json; // Is equivilent to this...var file = '/a/b/c';file;
json.File ( String filePath )
JSON File object constructor. Takes a path to a JSON file.
var file = '/path/to/file.json';
File::read ( Function callback )
Reads the JSON file and parses the contents.
file;
File::readSync ( void )
Reads the JSON file and parses the contents synchronously.
File::write ( Function callback )
Write the new contents back to the file.
file;
File::writeSync ( void )
Write the new contents back to the file synchronously.
File::get ( Mixed key )
Get a value from the JSON data.
file; // === file.data['foo']file; // === file.data['foo']['bar']['baz']
File::set ( Mixed key, Mixed value )
Set a value in the JSON data.
file;file;
The set
method returns the file object itself, so this method can be chained.
file ;