Clean up event service to use readJson

Use multiple level direct read.

Tested: Visual only. Need help if anyone wants to test.

Change-Id: I8655e74d39edcbab43fcd2a8379b085e91ed00eb
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 8bc8f9b..aebc282 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -285,8 +285,8 @@
         std::optional<std::vector<std::string>> msgIds;
         std::optional<std::vector<std::string>> regPrefixes;
         std::optional<std::vector<std::string>> resTypes;
-        std::optional<std::vector<nlohmann::json>> headers;
-        std::optional<std::vector<nlohmann::json>> mrdJsonArray;
+        std::optional<std::vector<nlohmann::json::object_t>> headers;
+        std::optional<std::vector<nlohmann::json::object_t>> mrdJsonArray;
 
         if (!json_util::readJsonPatch(
                 req, asyncResp->res, "Destination", destUrl, "Context", context,
@@ -467,32 +467,33 @@
         {
             size_t cumulativeLen = 0;
 
-            for (const nlohmann::json& headerChunk : *headers)
+            for (const nlohmann::json::object_t& headerChunk : *headers)
             {
-                std::string hdr{headerChunk.dump(
-                    -1, ' ', true, nlohmann::json::error_handler_t::replace)};
-                cumulativeLen += hdr.length();
-
-                // This value is selected to mirror http_connection.hpp
-                constexpr const uint16_t maxHeaderSizeED = 8096;
-                if (cumulativeLen > maxHeaderSizeED)
-                {
-                    messages::arraySizeTooLong(asyncResp->res, "HttpHeaders",
-                                               maxHeaderSizeED);
-                    return;
-                }
-                for (const auto& item : headerChunk.items())
+                for (const auto& item : headerChunk)
                 {
                     const std::string* value =
-                        item.value().get_ptr<const std::string*>();
+                        item.second.get_ptr<const std::string*>();
                     if (value == nullptr)
                     {
                         messages::propertyValueFormatError(
-                            asyncResp->res, item.value(),
-                            "HttpHeaders/" + item.key());
+                            asyncResp->res, item.second,
+                            "HttpHeaders/" + item.first);
                         return;
                     }
-                    subValue->httpHeaders.set(item.key(), *value);
+                    // Adding a new json value is the size of the key, +
+                    // the size of the value + 2 * 2 quotes for each, +
+                    // the colon and space between. example:
+                    // "key": "value"
+                    cumulativeLen += item.first.size() + value->size() + 6;
+                    // This value is selected to mirror http_connection.hpp
+                    constexpr const uint16_t maxHeaderSizeED = 8096;
+                    if (cumulativeLen > maxHeaderSizeED)
+                    {
+                        messages::arraySizeTooLong(
+                            asyncResp->res, "HttpHeaders", maxHeaderSizeED);
+                        return;
+                    }
+                    subValue->httpHeaders.set(item.first, *value);
                 }
             }
         }
@@ -596,12 +597,12 @@
 
         if (mrdJsonArray)
         {
-            for (nlohmann::json& mrdObj : *mrdJsonArray)
+            for (nlohmann::json::object_t& mrdObj : *mrdJsonArray)
             {
                 std::string mrdUri;
 
-                if (!json_util::readJson(mrdObj, asyncResp->res, "@odata.id",
-                                         mrdUri))
+                if (!json_util::readJsonObject(mrdObj, asyncResp->res,
+                                               "@odata.id", mrdUri))
 
                 {
                     return;
@@ -705,7 +706,7 @@
 
         std::optional<std::string> context;
         std::optional<std::string> retryPolicy;
-        std::optional<std::vector<nlohmann::json>> headers;
+        std::optional<std::vector<nlohmann::json::object_t>> headers;
 
         if (!json_util::readJsonPatch(req, asyncResp->res, "Context", context,
                                       "DeliveryRetryPolicy", retryPolicy,
@@ -722,23 +723,23 @@
         if (headers)
         {
             boost::beast::http::fields fields;
-            for (const nlohmann::json& headerChunk : *headers)
+            for (const nlohmann::json::object_t& headerChunk : *headers)
             {
-                for (const auto& it : headerChunk.items())
+                for (const auto& it : headerChunk)
                 {
                     const std::string* value =
-                        it.value().get_ptr<const std::string*>();
+                        it.second.get_ptr<const std::string*>();
                     if (value == nullptr)
                     {
                         messages::propertyValueFormatError(
-                            asyncResp->res, it.value(),
-                            "HttpHeaders/" + it.key());
+                            asyncResp->res, it.second,
+                            "HttpHeaders/" + it.first);
                         return;
                     }
-                    fields.set(it.key(), *value);
+                    fields.set(it.first, *value);
                 }
             }
-            subValue->httpHeaders = fields;
+            subValue->httpHeaders = std::move(fields);
         }
 
         if (retryPolicy)