Skip to content

Raynos/node-json-file

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#json-file-plus Version Badge

Build Status dependency status

A module to read from and write to JSON files, without losing formatting, to minimize diffs.

Example

var jsonFile = require('json-file-plus');
jsonFile.read('package.json', function (err, file) {
	if (err) { return doSomethingWithError(err); }

	file.data; // Direct access to the data from the file
	file.format; // extracted formatting data. change at will.

	file.get('version'); // get top-level keys, synchronously
	file.get('version', callback); // get top-level keys, asynchronously
	file.get(); // get entire data, synchronously
	file.get(callback); // get entire data, asynchronously

	/* pass any plain object into "set" to merge in a deep copy */
	/* please note: references will be broken. */
	/* if a non-plain object is passed, will throw a TypeError. */
	file.set({
		foo: 'bar',
		bar: {
			baz: true
		}
	});

	/* Save the file, preserving formatting. */
	/* Callback will be passed to fs.writeFile */
	file.save('new-package.json', fsWriteFileCallback);
});

Tests

Simply run npm test in the repo

About

Read from and write to a JSON file, minimizing diffs and preserving formatting.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%