aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/json-utils.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/json-utils.hh')
-rw-r--r--src/libutil/json-utils.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libutil/json-utils.hh b/src/libutil/json-utils.hh
new file mode 100644
index 000000000..eb00e954f
--- /dev/null
+++ b/src/libutil/json-utils.hh
@@ -0,0 +1,22 @@
+#pragma once
+///@file
+
+#include <nlohmann/json.hpp>
+
+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;
+}
+
+}