function toJson(obj, pretty) {
  if (typeof obj === 'undefined') return undefined;
  return JSON.stringify(obj, toJsonReplacer, pretty ? '  ' : null);
}
@ngdoc function
@name angular.toJson
@function

@description
Serializes input into a JSON-formatted string. Properties with leading $ characters will be
stripped since angular uses this notation internally.

@param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
@param {boolean=} pretty If set to true, the JSON output will contain newlines and whitespace.
@returns {string|undefined} JSON-ified string representing `obj`.