Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

writejson License NPM version Dependency Status Build Status

Write stringified object to file.

Install

npm i writejson --save

How to use?

To handle formating optional argument options could be used accroding to JSON.stringify.

API

writejson(name, object, [ options, ] callback)

Asynchonouse write stringified object.

var writejson = require('writejson');

writejson('data.json', {hello: 'world'}, function(error) {
    if (error)
        console.error(error.message);
});

var options = {
    replacer: ['hello'],// properties to put in json
    space: 4            // default space count
    eof: true           // default new line at end of file
};

writejson('data.json', {hello: 'world'}, options, function(error) {
    if (error)
        console.error(error.message);
});

writejson.sync(name, object [, options])

Synchonouse write stringified object.

try {
    writejson.sync('data.json', {hello: 'world'});
} catch(error) {
    console.log(error.message);
}

writejson.sync.try(name, object [, options])

Synchonouse try to write stringified object.

writejson.sync.try('data.json', {hello: 'world'});

License

MIT

About

write stringified object to file

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages