import re


def normalize(obj):
  """Normalize output object.

  Args:
     obj: Google Test's JSON output object to normalize.

  Returns:
     Normalized output without any references to transient information that may
     change from run to run.
  """
  def _normalize(key, value):
    if key == 'time':
      return re.sub(r'^\d+(\.\d+)?s$', '*', value)
    elif key == 'timestamp':
      return re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$', '*', value)
    elif key == 'failure':
      value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
      return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
    else:
      return normalize(value)
  if isinstance(obj, dict):
    return {k: _normalize(k, v) for k, v in obj.items()}
  if isinstance(obj, list):
    return [normalize(x) for x in obj]
  else:
    return obj