Filesystem.readJson()

Read and parse JSON file located at source path on disk into usable data.

Assumes file is encoded using utf8.

Usage

Hover over inputs/exits for more info.

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


// Read and parse JSON file located at source path on disk into usable data.

Filesystem.readJson({

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

schema: ,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// No file could be found at the provided `source` path.

doesNotExist: function () {

 

},

// Could not parse the file as JSON.

couldNotParse: function () {

 

},

// The specified path pointed to a directory.

isDirectory: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

source required

Absolute path to the source 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.

doesNotExist

No file could be found at the provided `source` path.

couldNotParse

Could not parse the file as JSON.

isDirectory

The specified path pointed to a directory.

success

OK.

(varies based on provided inputs)