Repository: google/benchmark
File: src/json_reporter.cc (C++)

Code before:
        return "iteration";
      case BenchmarkReporter::Run::RT_Aggregate:
        return "aggregate";
    }
    BENCHMARK_UNREACHABLE();
  }()) << ",\n";
  out << indent << FormatKV("repetitions", run.repetitions) << ",\n";
  if (run.run_type != BenchmarkReporter::Run::RT_Aggregate) {
    out << indent << FormatKV("repetition_index", run.repetition_index)
        << ",\n";
  }
  out << indent << FormatKV("threads", run.threads) << ",\n";
  if (run.run_type == BenchmarkReporter::Run::RT_Aggregate) {
    out << indent << FormatKV("aggregate_name", run.aggregate_name) << ",\n";
    out << indent << FormatKV("aggregate_unit", [&run]() -> const char* {
      switch (run.aggregate_unit) {
        case StatisticUnit::kTime:
          return "time";
        case StatisticUnit::kPercentage:
          return "percentage";
      }
      BENCHMARK_UNREACHABLE();
    }()) << ",\n";
  }
  if (run.skipped) {
    if (run.skip_is_error) {
      out << indent << FormatKV("error_occurred", run.skip_is_error) << ",\n";
      out << indent << FormatKV("error_message", run.skip_message) << ",\n";
    } else {
      out << indent << FormatKV("skipped", run.skipped) << ",\n";
      out << indent << FormatKV("skip_message", run.skip_message) << ",\n";
    }
  }
  if (!run.report_big_o && !run.report_rms) {
    out << indent << FormatKV("iterations", run.iterations) << ",\n";
    if (run.run_type != Run::RT_Aggregate ||
        run.aggregate_unit == StatisticUnit::kTime) {
      out << indent << FormatKV("real_time", run.GetAdjustedRealTime())
          << ",\n";
      out << indent << FormatKV("cpu_time", run.GetAdjustedCPUTime());
    } else {
      assert(run.aggregate_unit == StatisticUnit::kPercentage);
      out << indent << FormatKV("real_time", run.real_accumulated_time)
          << ",\n";
      out << indent << FormatKV("cpu_time", run.cpu_accumulated_time);
    }
    out << ",\n"
        << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_big_o) {
    out << indent << FormatKV("cpu_coefficient", run.GetAdjustedCPUTime())
        << ",\n";

Review comment (suggestion):
this could be a if..else if.. statement to remove the nesting if's but i feel like the logic is easier to follow this way

Code after:
        return "iteration";
      case BenchmarkReporter::Run::RT_Aggregate:
        return "aggregate";
    }
    BENCHMARK_UNREACHABLE();
  }()) << ",\n";
  out << indent << FormatKV("repetitions", run.repetitions) << ",\n";
  if (run.run_type != BenchmarkReporter::Run::RT_Aggregate) {
    out << indent << FormatKV("repetition_index", run.repetition_index)
        << ",\n";
  }
  out << indent << FormatKV("threads", run.threads) << ",\n";
  if (run.run_type == BenchmarkReporter::Run::RT_Aggregate) {
    out << indent << FormatKV("aggregate_name", run.aggregate_name) << ",\n";
    out << indent << FormatKV("aggregate_unit", [&run]() -> const char* {
      switch (run.aggregate_unit) {
        case StatisticUnit::kTime:
          return "time";
        case StatisticUnit::kPercentage:
          return "percentage";
      }
      BENCHMARK_UNREACHABLE();
    }()) << ",\n";
  }
  if (internal::SkippedWithError == run.skipped) {
    out << indent << FormatKV("error_occurred", true) << ",\n";
    out << indent << FormatKV("error_message", run.skip_message) << ",\n";
  } else if (internal::SkippedWithMessage == run.skipped) {
    out << indent << FormatKV("skipped", true) << ",\n";
    out << indent << FormatKV("skip_message", run.skip_message) << ",\n";
  }
  if (!run.report_big_o && !run.report_rms) {
    out << indent << FormatKV("iterations", run.iterations) << ",\n";
    if (run.run_type != Run::RT_Aggregate ||
        run.aggregate_unit == StatisticUnit::kTime) {
      out << indent << FormatKV("real_time", run.GetAdjustedRealTime())
          << ",\n";
      out << indent << FormatKV("cpu_time", run.GetAdjustedCPUTime());
    } else {
      assert(run.aggregate_unit == StatisticUnit::kPercentage);
      out << indent << FormatKV("real_time", run.real_accumulated_time)
          << ",\n";
      out << indent << FormatKV("cpu_time", run.cpu_accumulated_time);
    }
    out << ",\n"
        << indent << FormatKV("time_unit", GetTimeUnitString(run.time_unit));
  } else if (run.report_big_o) {
    out << indent << FormatKV("cpu_coefficient", run.GetAdjustedCPUTime())
        << ",\n";
    out << indent << FormatKV("real_coefficient", run.GetAdjustedRealTime())
        << ",\n";