Move WebRTC to non deprecated jsoncpp APIs.

This will allow the removal of -Wno-deprecated-declarations from
WebRTC's BUILD.gn files even if [1] will still propagate in the
build graph, causing some ABSL_DEPRECATED to be ignored.

[1] - https://source.chromium.org/chromium/chromium/src/+/main:third_party/jsoncpp/BUILD.gn;l=15;drc=592d07510836410a1ec4833de342544d1b39ef08

Bug: webrtc:10770
Change-Id: I90193ac5cc3e41f00f1b5dd5dac3c462e4b5f9ef
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/223666
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34375}
diff --git a/api/audio/echo_canceller3_config_json.cc b/api/audio/echo_canceller3_config_json.cc
index 91a3c66..263599c 100644
--- a/api/audio/echo_canceller3_config_json.cc
+++ b/api/audio/echo_canceller3_config_json.cc
@@ -11,6 +11,7 @@
 
 #include <stddef.h>
 
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -156,9 +157,14 @@
   *parsing_successful = true;
 
   Json::Value root;
-  bool success = Json::Reader().parse(std::string(json_string), root);
+  Json::CharReaderBuilder builder;
+  std::string error_message;
+  std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+  bool success =
+      reader->parse(json_string.data(), json_string.data() + json_string.size(),
+                    &root, &error_message);
   if (!success) {
-    RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string;
+    RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << error_message;
     *parsing_successful = false;
     return;
   }
diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc
index 3488460..62b2c4d 100644
--- a/pc/rtc_stats_collector_unittest.cc
+++ b/pc/rtc_stats_collector_unittest.cc
@@ -951,9 +951,14 @@
   ExampleStatsGraph graph = SetupExampleStatsGraphForSelectorTests();
   rtc::scoped_refptr<const RTCStatsReport> report = stats_->GetStatsReport();
   std::string json_format = report->ToJson();
-  Json::Reader reader;
+
+  Json::CharReaderBuilder builder;
   Json::Value json_value;
-  ASSERT_TRUE(reader.parse(json_format, json_value));
+  std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+  ASSERT_TRUE(reader->parse(json_format.c_str(),
+                            json_format.c_str() + json_format.size(),
+                            &json_value, nullptr));
+
   // A very brief sanity check on the result.
   EXPECT_EQ(report->size(), json_value.size());
 }
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index c780e29..7ea069a 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -637,10 +637,6 @@
 config("rtc_json_suppressions") {
   if (!is_win || is_clang) {
     cflags_cc = [
-      # TODO(bugs.webrtc.org/10770): Update jsoncpp API usage and remove
-      # -Wno-deprecated-declarations.
-      "-Wno-deprecated-declarations",
-
       # TODO(bugs.webrtc.org/10814): Remove -Wno-undef as soon as it get
       # removed upstream.
       "-Wno-undef",
diff --git a/rtc_base/strings/json.cc b/rtc_base/strings/json.cc
index 8a544a0..9966440 100644
--- a/rtc_base/strings/json.cc
+++ b/rtc_base/strings/json.cc
@@ -286,9 +286,9 @@
 }
 
 std::string JsonValueToString(const Json::Value& json) {
-  Json::FastWriter w;
-  std::string value = w.write(json);
-  return value.substr(0, value.size() - 1);  // trim trailing newline
+  Json::StreamWriterBuilder builder;
+  std::string output = Json::writeString(builder, json);
+  return output.substr(0, output.size() - 1);  // trim trailing newline
 }
 
 }  // namespace rtc
diff --git a/rtc_tools/rtp_generator/rtp_generator.cc b/rtc_tools/rtp_generator/rtp_generator.cc
index 3180897..c2fc1cf 100644
--- a/rtc_tools/rtp_generator/rtp_generator.cc
+++ b/rtc_tools/rtp_generator/rtp_generator.cc
@@ -136,10 +136,15 @@
   }
 
   // Parse the file as JSON
-  Json::Reader json_reader;
+  Json::CharReaderBuilder builder;
   Json::Value json;
-  if (!json_reader.parse(raw_json_buffer.data(), json)) {
-    RTC_LOG(LS_ERROR) << "Unable to parse the corpus config json file";
+  std::string error_message;
+  std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
+  if (!json_reader->parse(raw_json_buffer.data(),
+                          raw_json_buffer.data() + raw_json_buffer.size(),
+                          &json, &error_message)) {
+    RTC_LOG(LS_ERROR) << "Unable to parse the corpus config json file. Error:"
+                      << error_message;
     return absl::nullopt;
   }
 
diff --git a/rtc_tools/video_replay.cc b/rtc_tools/video_replay.cc
index d96c7be..b655a88 100644
--- a/rtc_tools/video_replay.cc
+++ b/rtc_tools/video_replay.cc
@@ -399,11 +399,14 @@
     std::stringstream raw_json_buffer;
     raw_json_buffer << config_file.rdbuf();
     std::string raw_json = raw_json_buffer.str();
-    Json::Reader json_reader;
+    Json::CharReaderBuilder builder;
     Json::Value json_configs;
-    if (!json_reader.parse(raw_json, json_configs)) {
+    std::string error_message;
+    std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
+    if (!json_reader->parse(raw_json.data(), raw_json.data() + raw_json.size(),
+                            &json_configs, &error_message)) {
       fprintf(stderr, "Error parsing JSON config\n");
-      fprintf(stderr, "%s\n", json_reader.getFormatedErrorMessages().c_str());
+      fprintf(stderr, "%s\n", error_message.c_str());
       return nullptr;
     }
 
diff --git a/stats/rtc_stats_unittest.cc b/stats/rtc_stats_unittest.cc
index aff6ab3..2cad90d 100644
--- a/stats/rtc_stats_unittest.cc
+++ b/stats/rtc_stats_unittest.cc
@@ -267,9 +267,14 @@
   stats.m_sequence_string = sequence_string;
   stats.m_map_string_uint64 = map_string_uint64;
   stats.m_map_string_double = map_string_double;
+  std::string json_stats = stats.ToJson();
 
+  Json::CharReaderBuilder builder;
   Json::Value json_output;
-  EXPECT_TRUE(Json::Reader().parse(stats.ToJson(), json_output));
+  std::unique_ptr<Json::CharReader> json_reader(builder.newCharReader());
+  EXPECT_TRUE(json_reader->parse(json_stats.c_str(),
+                                 json_stats.c_str() + json_stats.size(),
+                                 &json_output, nullptr));
 
   EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "id", &id));
   EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "timestamp", &timestamp));