Added JSON option for gRPC file loading
diff --git a/src/node/index.js b/src/node/index.js
index 0b768ed..8757563 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -67,10 +67,25 @@
/**
* Load a gRPC object from a .proto file.
* @param {string} filename The file to load
+ * @param {string=} format The file format to expect. Must be either 'proto' or
+ * 'json'. Defaults to 'proto'
* @return {Object<string, *>} The resulting gRPC object
*/
-function load(filename) {
- var builder = ProtoBuf.loadProtoFile(filename);
+function load(filename, format) {
+ if (!format) {
+ format = 'proto';
+ }
+ var builder;
+ switch(format) {
+ case 'proto':
+ builder = ProtoBuf.loadProtoFile(filename);
+ break;
+ case 'json':
+ builder = ProtoBuf.loadJsonFile(filename);
+ break;
+ default:
+ throw new Error('Unrecognized format "' + format + '"');
+ }
return loadObject(builder.ns);
}