Run Mocha programmatically and pass results to variable or function

Hmm normally people would use a CI bot to achieve what you are trying to do. However, regarding your direct question about getting the result from JSON reporter, I don't know if there is a better way to achieve it, but here is what I'd do after reading the mocha source. You'll have to create the Suite, the Runner and get the reporter yourself (copy from https://github.com/mochajs/mocha/blob/master/test%2Freporters%2Fjson.js):

var mocha = new Mocha({
    reporter: 'json'
});
var suite = new Suite('JSON suite', 'root');
var runner = new Runner(suite);
var mochaReporter = new mocha._reporter(runner);

runner.run(function(failures) {
    // the json reporter gets a testResults JSON object on end
    var testResults = mochaReporter.testResults;
    // send your email here
});

I'd suggest using a mocha reporter as explained here https://github.com/mochajs/mocha/wiki/Third-party-reporters

invoke mocha like this

MyReporter = require('./MyReporter');
mocha({ reporter: MyReporter })`

and the MyReporter.js file will look like this

var mocha = require('mocha');
module.exports = MyReporter;

function MyReporter(runner) {
  mocha.reporters.Base.call(this, runner);
  var passes = 0;
  var failures = 0;

  runner.on('pass', function(test){
    passes++;
    console.log('pass: %s', test.fullTitle());
  });

  runner.on('fail', function(test, err){
    failures++;
    console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
  });

  runner.on('end', function(){
    console.log('end: %d/%d', passes, passes + failures);
    process.exit(failures);
  });
}

You can listen to the runner events as in https://github.com/mochajs/mocha/blob/master/lib/runner.js#L40 and build your own report.

var Mocha = require('mocha');

var mocha = new Mocha({});

mocha.addFile('/Users/dominic/Git/testing-rig/test/services/homepage.js')

mocha.run()
    .on('test', function(test) {
        console.log('Test started: '+test.title);
    })
    .on('test end', function(test) {
        console.log('Test done: '+test.title);
    })
    .on('pass', function(test) {
        console.log('Test passed');
        console.log(test);
    })
    .on('fail', function(test, err) {
        console.log('Test fail');
        console.log(test);
        console.log(err);
    })
    .on('end', function() {
        console.log('All done');
    });