aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/json-utils.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-06-16 15:19:14 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-06-18 23:31:10 -0400
commitc8825e9d8c3fa802811f3829d055e3ef9aae90e2 (patch)
tree590b8bf2103bb7e09d2fb72c930fe5542ee3d36d /src/libutil/json-utils.cc
parent3b0d8fd796336318ce03c8ee90cd40ebb65fb032 (diff)
Create nlohmann serializers for `std::optional` and use
This is somewhat tricky.
Diffstat (limited to 'src/libutil/json-utils.cc')
-rw-r--r--src/libutil/json-utils.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libutil/json-utils.cc b/src/libutil/json-utils.cc
new file mode 100644
index 000000000..d7220e71d
--- /dev/null
+++ b/src/libutil/json-utils.cc
@@ -0,0 +1,19 @@
+#include "json-utils.hh"
+
+namespace nix {
+
+const nlohmann::json * get(const nlohmann::json & map, const std::string & key)
+{
+ auto i = map.find(key);
+ if (i == map.end()) return nullptr;
+ return &*i;
+}
+
+nlohmann::json * get(nlohmann::json & map, const std::string & key)
+{
+ auto i = map.find(key);
+ if (i == map.end()) return nullptr;
+ return &*i;
+}
+
+}