Permalink
Browse files

Add -i flag to do sys.inspect output.

  • Loading branch information...
1 parent b37fee9 commit 8d3a722a1e3fadcbc48268f31d5707fef921e288 @isaacs isaacs committed Dec 21, 2010
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/jsonCommand.js
View
@@ -14,6 +14,7 @@ JSON.Command = function(args) {
this.keys = [];
this.transformedKeys = [];
this.uglyOutput = false;
+ this.inspectOutput = false;
this.columnOutput = false;
this.useObject = null;
@@ -45,6 +46,7 @@ JSON.Command.prototype.printhelp = function() {
sys.puts(" -C print the output fields as tab delimited columns in");
sys.puts(" the order specified by fields\n");
sys.puts(" -e \"js expression\" execute arbitrary js in the context of each object.\n");
+ sys.puts(" -i use node's sys.inspect instead of JSON.stringify\n");
sys.puts("examples:\n");
sys.puts(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
sys.puts(" json -o results\n");
@@ -58,7 +60,9 @@ JSON.Command.prototype.printhelp = function() {
};
JSON.Command.prototype.stringify = function(obj) {
- return(this.uglyOutput ? JSON.stringify(obj) : JSON.stringify(obj, null, 2));
+ return( this.inspectOutput ? sys.inspect(obj, false, Infinity, true)
+ : this.uglyOutput ? JSON.stringify(obj)
+ : JSON.stringify(obj, null, 2) );
};
JSON.Command.prototype.debug = function(msg) {
@@ -105,6 +109,9 @@ JSON.Command.prototype.processArgs = function processArgs(args) {
case "-o": // use object
this.useObject = a.shift();
break;
+ case "-i": // use sys.inspect
+ this.inspectOutput = true;
+ break;
default: // json object keys
if (arg.match("=")) {
var kk = arg.split("=");

0 comments on commit 8d3a722

Please sign in to comment.