diff --git a/bin/dogapi b/bin/dogapi index ad28513..78bffe5 100755 --- a/bin/dogapi +++ b/bin/dogapi @@ -1,5 +1,6 @@ #!/usr/bin/env node var dogapi = require("../"); +var json = require("../lib/json"); var minimist = require("minimist"); var rc = require("rc"); @@ -56,13 +57,13 @@ if(command === "now"){ if(subcommand){ dogapi[command].handleCli(subcommand, args, function(err, res){ if(err){ - console.error(JSON.stringify(err, null, ' ')); + console.error(json.stringify(err, null, ' ')); process.exit(1); } else { if(res === ""){ res = "success"; } - console.log(JSON.stringify(res, null, ' ')); + console.log(json.stringify(res, null, ' ')); } }); } else { diff --git a/lib/api/screenboard.js b/lib/api/screenboard.js index f58cca7..aeac641 100644 --- a/lib/api/screenboard.js +++ b/lib/api/screenboard.js @@ -1,4 +1,5 @@ var client = require("../client"); +var json = require("../json"); var util = require("util"); @@ -218,11 +219,11 @@ module.exports = { } else if(subcommand === "create"){ var title = args._[4]; var description = args._[5]; - var graphs = JSON.parse(args._[6]); + var graphs = json.parse(args._[6]); var options = {}; if(args["tmpvars"]){ - options.templateVariables = JSON.parse(args["tmpvars"]); + options.templateVariables = json.parse(args["tmpvars"]); } if(args["width"]){ options.width = parseInt(args["width"]); diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index c2c4e18..20e8400 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -1,4 +1,5 @@ var client = require("../client"); +var json = require("../json"); var util = require("util"); /*section: timeboard @@ -249,10 +250,10 @@ module.exports = { } else if(subcommand === "create"){ var title = args._[4]; var description = args._[5]; - var graphs = JSON.parse(args._[6]); + var graphs = json.parse(args._[6]); var templateVariables = []; if(args["tmpvars"]){ - templateVariables = JSON.parse(args["tmpvars"]); + templateVariables = json.parse(args["tmpvars"]); } create(title, description, graphs, templateVariables, callback); @@ -260,10 +261,10 @@ module.exports = { var dashId = parseInt(args._[4]); var title = args._[5]; var description = args._[6]; - var graphs = JSON.parse(args._[7]); + var graphs = json.parse(args._[7]); var templateVariables = []; if(args["tmpvars"]){ - templateVariables = JSON.parse(args["tmpvars"]); + templateVariables = json.parse(args["tmpvars"]); } update(dashId, title, description, graphs, templateVariables, callback); diff --git a/lib/client.js b/lib/client.js index 88b209e..14071dd 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,5 +1,6 @@ var extend = require("extend"); var https = require("https"); +var json = require("./json"); var url = require("url"); var util = require("util"); @@ -50,7 +51,7 @@ client.prototype.request = function(method, path, params, callback){ } params = params || {}; - var body = (typeof params["body"] === "object")? JSON.stringify(params["body"]) : params["body"]; + var body = (typeof params["body"] === "object")? json.stringify(params["body"]) : params["body"]; var query = { "api_key": this.api_key, "application_key": this.app_key, @@ -97,7 +98,7 @@ client.prototype.request = function(method, path, params, callback){ res.on("end", function(){ var error = null; - try{ data = JSON.parse(data); }catch(e){} + try{ data = json.parse(data); }catch(e){} if(data["errors"]){ error = data["errors"]; data = null; diff --git a/lib/json.js b/lib/json.js new file mode 100644 index 0000000..95f3648 --- /dev/null +++ b/lib/json.js @@ -0,0 +1,7 @@ +var JSONBig = require("json-bigint"); + + +module.exports = { + stringify: JSONBig.stringify, + parse: JSONBig.parse +}; diff --git a/package.json b/package.json index f038102..4ad9b22 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc", "dependencies": { "extend": "^2.0.0", + "json-bigint": "^0.1.4", "minimist": "^1.1.1", "rc": "^1.0.0" },