从当前工作目录下读取 JSON 文件返回 JS 对象

@param {string} path
@return {object}
184468
function readJson(filePath) {
    var json = {};

    try {
        var content = fs.readFileSync(path.resolve(process.cwd(), filePath), {
            encoding: 'utf-8'
        });
        json = JSON.parse(stripJsonComments(content));
    } catch (error) {
        console.error(error);
    }

    return json;
}
141442
function readFile(path) {
  try {
    const contents = fs.readFileSync(path, { encoding: 'utf8' });

    return contents;
  } catch (error) {
    throw new Error(error);
  }
}
540305
public Object getDataJson(String path) throws ZooKeeperException {
        try {
            Object data = getFromCache(cacheNameJson, path);
            if (data == null) {
                data = _readJson(path);
                putToCache(cacheNameJson, path, data);
            }
            return data;
        } catch (ZooKeeperException.NodeNotFoundException e) {
            return null;
        } catch (Exception e) {
            if (e instanceof ZooKeeperException) {
                throw (ZooKeeperException) e;
            } else {
                throw new ZooKeeperException(e);
            }
        }
    }
1077234
function loadJSON( path ) {
    return new Promise( function( resolve, reject ) {
        var xhr = new XMLHttpRequest( {
            mozSystem: true
        } );
        xhr.onload = function() {
            var text = xhr.responseText;
            try {
                resolve( JSON.parse( text ) );
            } catch ( ex ) {
                reject( Error( "Bad JSON format for \"" + path + "\"!\n" + ex + "\n" + text ) );
            }
        };
        xhr.onerror = function() {
            reject( Error( "Unable to load file \"" + path + "\"!\n" + xhr.statusText ) );
        };
        xhr.open( "GET", path, true );
        xhr.withCredentials = true; // Indispensable pour le CORS.
        xhr.send();
    } );
}
257680
function parsePackageJson(path) {
    return fs.readFile(path)
        .catch(function () {
            var err = new Error(common.i18n.t('errors.utils.parsepackagejson.couldNotReadPackage'));
            err.context = path;

            return Promise.reject(err);
        })
        .then(function (source) {
            var hasRequiredKeys, json, err;

            try {
                json = JSON.parse(source);

                hasRequiredKeys = json.name && json.version;

                if (!hasRequiredKeys) {
                    err = new Error(common.i18n.t('errors.utils.parsepackagejson.nameOrVersionMissing'));
                    err.context = path;
                    err.help = common.i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'https://docs.ghost.org/api/handlebars-themes/'});

                    return Promise.reject(err);
                }

                return json;
            } catch (parseError) {
                err = new Error(common.i18n.t('errors.utils.parsepackagejson.themeFileIsMalformed'));
                err.context = path;
                err.help = common.i18n.t('errors.utils.parsepackagejson.willBeRequired', {url: 'https://docs.ghost.org/api/handlebars-themes/'});

                return Promise.reject(err);
            }
        });
}
1208297
function readJSON(filepath){
	var buffer = {};
	try{
		buffer = JSON.parse(fs.readFileSync(filepath, { encoding:'utf8' }));
	} catch(error){}
	return buffer;
}
1267430
function get(path) {
    var conf = this;

    if (typeof path !== 'string') {
        throw new Error('path should be a string!');
    } else if (path.length === 0) {
        throw new Error('path cannot be empty!');
    }

    var result = baseGet(conf, getPathArray(path));
    if (result === undefined) {
        throw new Error('the value is undefined!');
    } else {
        bindGetMethod(result);  // eslint-disable-line
    }

    return result;
}
926204
function getFile(path) {
	const
		cache = validateCache(path, filesCache);

	if (!cache.fromCache) {
		filesCache[path] = {
			mtime: cache.mtime,
			content: fs.readFileSync(path, 'utf-8')
		};
	}

	return filesCache[path].content;
}
1316819
public static ConfigurableJsonMatcher<String> jsonStringPartEquals(String path, Object expected) {
        return jsonPartEquals(path, expected);
    }
973120
function getMime(path) {
          var index = String(path).lastIndexOf(".");
          if (index < 0) {
              return defaultMime;
          }
          var type = exports.mime.types[path.substring(index).toLowerCase()] || defaultMime;
          return (/(text|javascript)/).test(type)
            ? type + "; charset=utf-8"
            : type;
      }
492106
function readDB(path)
{
    return readFileAsync(path)
        .then((jsonStr) =>
        {
            try
            {
                return JSON.parse(jsonStr);
            }
            catch(ex)
            {
                // Wrap the exception in a more friendly one.
                const error = new Error("Failed to parse on disk json file.");
                error.code = 'ERR_JSON_PARSE';
                error.innerException = ex;

                // Throw the error
                throw error;
            } // end try/catch
        });
}
585829
function parseJSON( path, content ) {

            return JSON.parse( content, function( key, value ) {

                if ( options.stripComments && key === "{{comment}}" ) return undefined;

                // Replace variables in their values

                if ( Object.keys( options.variables ).length && typeof value === "string" ) {
                    value = replaceVariables( value );
                }

                var match = ( typeof value === "string" ) ? value.match( options.parsePattern ) : null;

                if ( match ) {
                    var folderPath = getFolder( path ) || ".";
                    var fullPath = folderPath + "/" + match[ 1 ];

                    return isDirectory( fullPath ) ? parseDirectory( fullPath ) : parseFile( fullPath );
                }

                return value;

            } );
        }
915317
function loadJson(filepath) {
	const json = fs.readFileSync(require.resolve(filepath), 'utf8');
	return JSON.parse(stripJsonComments(json));
}
605833
function readJSON(path) {
  return new Promise(function ($return, $error) {
    var file, parsed;
    return Promise.resolve(read(path)).then(function ($await_1) {
      try {
        file = $await_1;
        parsed = JSON.parse(file);
        return $return(parsed);
      } catch ($boundEx) {
        return $error($boundEx);
      }
    }.bind(this), $error);
  }.bind(this));
}
543625
function jsonEncoder(input, path) {
    var output = new Stream();
    output.readable = true;
    var first = true;
    input.on("data", function (entry) {
      if (path) {
        entry.href = path + entry.name;
        var mime = entry.linkStat ? entry.linkStat.mime : entry.mime;
        if (mime && mime.match(/(directory|folder)$/)) {
          entry.href += "/";
        }
      }
      if (first) {
        output.emit("data", "[\n  " + JSON.stringify(entry));
        first = false;
      } else {
        output.emit("data", ",\n  " + JSON.stringify(entry));
      }
    });
    input.on("end", function () {
      if (first) output.emit("data", "[]");
      else output.emit("data", "\n]");
      output.emit("end");
    });
    if (input.pause) {
      output.pause = function () {
        input.pause();
      };
    }
    if (input.resume) {
      output.resume = function () {
        input.resume();
      };
    }
    return output;
  }
857242
function getPath( object , path ) {
	var i = 0 , iMax = path.length , p = object ;

	//console.log( "getPath():" , object , path ) ;

	try {
		for ( ; i < iMax ; i ++ ) {
			//console.log( "Next path:" , path[ i ] ) ;
			p = p[ path[ i ] ] ;
		}
	}
	catch ( error ) {
		throw new Error( "Bad ref: path not found" ) ;
	}

	return p ;
}
207201
function getFromPath(obj, path){
		path = path.split('.');

		for(var i = 0, l = path.length; i < l; i++){
			if (hasOwnProperty.call(obj, path[i]))
				obj = obj[path[i]];
			
			else
				return undefined;
		}
		
		return obj;
	}