node package manager


A module for modifiying JSON files


A Node.js module for reading/modifying/writing JSON files.

$ npm install json-file
var json = require('json-file');
// Load a JSON file 
var file ='./package.json');
// Read and write some values 
file.get('version');  // eg. "1.0.0" 
file.get('repository.type');  // eg. "git" 
file.set('description', 'Some new description');
// The raw data 
// Write the updates to the file 

A shortcut for creating a json.File object and loading the file contents.

// This... 
var file ='/a/b/c');
// Is equivilent to this... 
var file = new json.File('/a/b/c');
// Likewise, this... 
var file ='/a/b/c', function() {
// ... 
// Is equivilent to this... 
var file = new json.File('/a/b/c'); {
// ... 

JSON File object constructor. Takes a path to a JSON file.

var file = new json.File('/path/to/file.json');

Reads the JSON file and parses the contents. {
// Now you can do things like use the .get() and .set() methods 

Reads the JSON file and parses the contents synchronously.

Write the new contents back to the file.

file.write(function() {
// Your JSON file has been updated 

Write the new contents back to the file synchronously.

Get a value from the JSON data.

file.get('foo'); // ===['foo'] 
file.get(''); // ===['foo']['bar']['baz'] 

Set a value in the JSON data.

file.set('foo', 'bar');
file.set('a.b.c', 'baz');

The set method returns the file object itself, so this method can be chained.

file.set('a', 'foo')
    .set('b', 'bar')
    .set('c', 'baz');