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 exists at the provided `source` path

doesNotExist: function () {

 

},

// Could not parse file as JSON.

couldNotParse: 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 exists at the provided `source` path

couldNotParse

Could not parse file as JSON.

success

OK.

(varies based on provided inputs)