summaryrefslogtreecommitdiff
path: root/src/squelch/jsoncons_helpers.hpp
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2020-05-27 16:31:00 -0700
committerManoj Srivastava <srivasta@debian.org>2020-05-27 16:31:00 -0700
commitd7533e931cfb49a68dc8e6e3f524d49e364cef83 (patch)
tree06d31523b9647d3de8ce8888f6e83d24f046aa82 /src/squelch/jsoncons_helpers.hpp
parent4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff)
New upstream version 2.41-ah~0.git.20200131
Diffstat (limited to 'src/squelch/jsoncons_helpers.hpp')
-rw-r--r--src/squelch/jsoncons_helpers.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/squelch/jsoncons_helpers.hpp b/src/squelch/jsoncons_helpers.hpp
new file mode 100644
index 00000000..1ce6b094
--- /dev/null
+++ b/src/squelch/jsoncons_helpers.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <boost/optional.hpp>
+#include <jsoncons/json.hpp>
+#include <string>
+
+namespace squelch {
+
+template <class T>
+boost::optional<T> get_optional(jsoncons::json const &json, std::string const &key)
+{
+ if (!json.has_key(key))
+ {
+ return boost::none;
+ }
+
+ auto value = json.at(key);
+
+ if (!value.is<T>())
+ {
+ return boost::none;
+ }
+
+ return value.as<T>();
+}
+
+} // namespace squelch