Format log JSON

var exampleObj = {
    "name": "Tim",
    "age": 31,
    "groovy": true,
    "dogs": [
        {
            "name": "Ezri",
            "age": 1
        },
        {
            "name": "Seven",
            "age": 3
        }
    ]
};

gs.info(
    'Logging JSON objects can be very useful, but they need to be stringified first. If we ' +
    'just stringify them in the usual way, we get something that\'s kind of hard to read, like this: \n' +
    '{0}\n\n' +
    'But, we can do better, by specifying some additional parameters to the .stringify() method like ' +
    'so: JSON.stringify(exampleObj, null, 2) : \n{1}',
    JSON.stringify(exampleObj),
    JSON.stringify(
        exampleObj,
        null, //A function or array to filter/replace some values of the object (useful if
        // you want to log an object, but not log potentially sensitive elements)
        2 //The number of spaces by which to indent child-elements. You can also specify a
        // string or escape character such as '\t' for tabs.
    )
);
/*
    Output: Logging JSON objects can be very useful, but they need to be stringified first. If we just
    stringify them in the usual way, we get something that's kind of hard to read, like this:
    {"name":"Tim","age":31,"groovy":true,"dogs":[{"name":"Ezri","age":1},{"name":"Seven","age":3}]}
    
    But, we can do better, by specifying some additional parameters to the .stringify() method like
    so: JSON.stringify(exampleObj, null, 2) :
    {
      "name": "Tim",
      "age": 31,
      "groovy": true,
      "dogs": [
        {
          "name": "Ezri",
          "age": 1
        },
        {
          "name": "Seven",
          "age": 3
        }
      ]
    }
*/

//More on the stringify method here:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
Envious Elk