From efc1b9df6264133d009313e5c520675914ebbca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=95=EC=A4=80?= Date: Fri, 5 Aug 2022 11:39:33 +0900 Subject: [PATCH] added nlohmann::json operator+ Add a simple plus operator to easily combine json objects --- include/nlohmann/json.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 49188b314..1a194e8b7 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5074,6 +5074,22 @@ std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j) return j.dump(); } +inline nlohmann::json operator+(const nlohmann::json& lhs, const nlohmann::json& rhs) +{ + nlohmann::json ret; + for (const auto& el : lhs.items()) + { + ret[el.key()] = el.value(); + } + + for (const auto& el : rhs.items()) + { + ret[el.key()] = el.value(); + } + + return ret; +} + inline namespace literals { inline namespace json_literals