public static JsonObject transformToJson(RTCStatList stats) {
    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
    for (RTCStats stat: stats) {
      JsonObject temp = stat.toJson();
      if (!temp.isEmpty()) {
        arrayBuilder.add(stat.toJson());
      }
    }
    JsonObjectBuilder rtn =  Json.createObjectBuilder()
        .add("Connected", !stats.hasNoData())
        .add("Room", stats.getRoomUrl())
        .add("StatsArray", arrayBuilder);

    for (String key : stats.getAdditionalData().keySet()) {
      rtn.add(key, stats.getAdditionalData().get(key));
    }
    return rtn.build();
  }
Transform list of RTCStats to list of Json Object

@param stats list of RTCStats object.

@return list of Json Object
KITE-Framework/src/main/java/org/webrtc/kite/stats/StatsUtils.java