Remove the last instances of json pattern

In the past, we've tried to erradicate the use of
nlohmann::json(initiatlizer_list<...>) because it bloats binary sizes,
as every type is given a new nlohmann constructor.

This commit hunts down the last few places where we call this.  There is
still 2 remaining in openbmc_dbus_rest after this, but those are variant
accesses that are difficult to triage, and considering it's a less used
api, they're left as is.

Tested: WIP

Change-Id: Iaac24584bb78bb238da69010b511c1d598bd38bc
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 51437c9..c32412a 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -243,9 +243,8 @@
     asyncResp->res.jsonValue["Name"] = "ConfigFiles";
 
     asyncResp->res.jsonValue["Members"] = std::move(pathObjList);
-    asyncResp->res.jsonValue["Actions"]["#IBMConfigFiles.DeleteAll"] = {
-        {"target",
-         "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll"}};
+    asyncResp->res.jsonValue["Actions"]["#IBMConfigFiles.DeleteAll"]["target"] =
+        "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll";
 }
 
 inline void
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 72e1c31..a2f68b4 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2332,10 +2332,10 @@
                     const char* type = arg->Attribute("type");
                     if (name != nullptr && type != nullptr)
                     {
-                        argsArray.push_back({
-                            {"name", name},
-                            {"type", type},
-                        });
+                        nlohmann::json::object_t params;
+                        params["name"] = name;
+                        params["type"] = type;
+                        argsArray.push_back(std::move(params));
                     }
                     arg = arg->NextSiblingElement("arg");
                 }
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 0e1d3a1..4bfbdd8 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -38,6 +38,7 @@
 #include <ranges>
 #include <string>
 #include <string_view>
+#include <utility>
 #include <vector>
 
 namespace redfish
@@ -1907,9 +1908,12 @@
                             return;
                         }
                         asyncResp->res.jsonValue["Locked"] = *userLocked;
+                        nlohmann::json::array_t allowed;
+                        // can only unlock accounts
+                        allowed.emplace_back("false");
                         asyncResp->res
-                            .jsonValue["Locked@Redfish.AllowableValues"] = {
-                            "false"}; // can only unlock accounts
+                            .jsonValue["Locked@Redfish.AllowableValues"] =
+                            std::move(allowed);
                     }
                     else if (property.first == "UserPrivilege")
                     {
diff --git a/redfish-core/lib/bios.hpp b/redfish-core/lib/bios.hpp
index a0e440b..1ec967b 100644
--- a/redfish-core/lib/bios.hpp
+++ b/redfish-core/lib/bios.hpp
@@ -40,10 +40,9 @@
     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
     asyncResp->res.jsonValue["Id"] = "BIOS";
-    asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
-        {"target",
-         std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
-                     BMCWEB_REDFISH_SYSTEM_URI_NAME)}};
+    asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
+        std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
+                    BMCWEB_REDFISH_SYSTEM_URI_NAME);
 
     // Get the ActiveSoftwareImage and SoftwareImages
     sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 2524502..34a3aff 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1420,12 +1420,11 @@
         asyncResp->res.jsonValue["Entries"]["@odata.id"] =
             std::format("/redfish/v1/Systems/{}/LogServices/EventLog/Entries",
                         BMCWEB_REDFISH_SYSTEM_URI_NAME);
-        asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
+        asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"]
 
-            {"target",
-             std::format(
-                 "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
-                 BMCWEB_REDFISH_SYSTEM_URI_NAME)}};
+            = std::format(
+                "/redfish/v1/Systems/{}/LogServices/EventLog/Actions/LogService.ClearLog",
+                BMCWEB_REDFISH_SYSTEM_URI_NAME);
     });
 }
 
@@ -3989,11 +3988,10 @@
         asyncResp->res.jsonValue["DateTimeLocalOffset"] =
             redfishDateTimeOffset.second;
 
-        asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
-            {"target",
-             std::format(
-                 "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
-                 BMCWEB_REDFISH_SYSTEM_URI_NAME)}};
+        asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]
+                                ["target"] = std::format(
+            "/redfish/v1/Systems/{}/LogServices/PostCodes/Actions/LogService.ClearLog",
+            BMCWEB_REDFISH_SYSTEM_URI_NAME);
     });
 }
 
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index 7cd55b2..a0f4f34 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -21,8 +21,11 @@
 #include "registries/privilege_registry.hpp"
 
 #include <boost/url/format.hpp>
+#include <nlohmann/json.hpp>
 #include <sdbusplus/asio/property.hpp>
 
+#include <optional>
+#include <string_view>
 #include <variant>
 namespace redfish
 {
@@ -44,27 +47,34 @@
     return "";
 }
 
-inline bool getAssignedPrivFromRole(std::string_view role,
-                                    nlohmann::json& privArray)
+inline std::optional<nlohmann::json::array_t>
+    getAssignedPrivFromRole(std::string_view role)
 {
+    nlohmann::json::array_t privArray;
     if (role == "Administrator")
     {
-        privArray = {"Login", "ConfigureManager", "ConfigureUsers",
-                     "ConfigureSelf", "ConfigureComponents"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureManager");
+        privArray.emplace_back("ConfigureUsers");
+        privArray.emplace_back("ConfigureSelf");
+        privArray.emplace_back("ConfigureComponents");
     }
     else if (role == "Operator")
     {
-        privArray = {"Login", "ConfigureSelf", "ConfigureComponents"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureSelf");
+        privArray.emplace_back("ConfigureComponents");
     }
     else if (role == "ReadOnly")
     {
-        privArray = {"Login", "ConfigureSelf"};
+        privArray.emplace_back("Login");
+        privArray.emplace_back("ConfigureSelf");
     }
     else
     {
-        return false;
+        return std::nullopt;
     }
-    return true;
+    return privArray;
 }
 
 inline void requestRoutesRoles(App& app)
@@ -79,8 +89,10 @@
         {
             return;
         }
-        nlohmann::json privArray = nlohmann::json::array();
-        if (!getAssignedPrivFromRole(roleId, privArray))
+
+        std::optional<nlohmann::json::array_t> privArray =
+            getAssignedPrivFromRole(roleId);
+        if (!privArray)
         {
             messages::resourceNotFound(asyncResp->res, "Role", roleId);
 
@@ -96,7 +108,7 @@
         asyncResp->res.jsonValue["RoleId"] = roleId;
         asyncResp->res.jsonValue["@odata.id"] =
             boost::urls::format("/redfish/v1/AccountService/Roles/{}", roleId);
-        asyncResp->res.jsonValue["AssignedPrivileges"] = std::move(privArray);
+        asyncResp->res.jsonValue["AssignedPrivileges"] = std::move(*privArray);
     });
 }
 
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 6b758e7..2687ecf 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -46,6 +46,7 @@
 #include <memory>
 #include <string>
 #include <string_view>
+#include <utility>
 #include <variant>
 #include <vector>
 
@@ -942,11 +943,19 @@
 
         BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr);
 
+        nlohmann::json::array_t allowed;
+        allowed.emplace_back("None");
+        allowed.emplace_back("Pxe");
+        allowed.emplace_back("Hdd");
+        allowed.emplace_back("Cd");
+        allowed.emplace_back("Diags");
+        allowed.emplace_back("BiosSetup");
+        allowed.emplace_back("Usb");
+
         asyncResp->res
             .jsonValue["Boot"]
-                      ["BootSourceOverrideTarget@Redfish.AllowableValues"] = {
-            "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
-
+                      ["BootSourceOverrideTarget@Redfish.AllowableValues"] =
+            std::move(allowed);
         if (bootModeStr !=
             "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
         {
@@ -1245,9 +1254,12 @@
         // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways,
         // and RetryAttempts. OpenBMC only supports Disabled and
         // RetryAttempts.
+        nlohmann::json::array_t allowed;
+        allowed.emplace_back("Disabled");
+        allowed.emplace_back("RetryAttempts");
         asyncResp->res
             .jsonValue["Boot"]["AutomaticRetryConfig@Redfish.AllowableValues"] =
-            {"Disabled", "RetryAttempts"};
+            std::move(allowed);
     });
 }