Filesystem.ensureJson()

Attempt to read from a JSON file, and if it does not exist, create it.

Assumes file is encoded using utf8.

Usage

Hover over inputs/exits for more info.

var Filesystem = require('machinepack-fs');


// Attempt to read from a JSON file, and if it does not exist, create it.

Filesystem.ensureJson({

path: '/Users/mikermcneil/.tmp/foo.json',

schema: '*',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Could not parse file as JSON.

couldNotParse: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

path required

Absolute path for the JSON file (if relative path is provided, will resolve path from current working directory)

'/Users/mikermcneil/.tmp/foo.json'
schema

An example schema (in RTTC exemplar syntax) describing what the parsed data should look like (used for type-coercion)

'*'

Exits

error

An unexpected error occurred.

couldNotParse

Could not parse file as JSON.

success

OK.

(varies based on provided inputs)