I am new to json parsing with boost using the property tree.
If I have this hash:
foo = {'test1',true}
ptree pt;
bool v = pt.get<bool>("test2");
I need to check a key exists and if not set it to false.
How do I do that gracefully?
Thanks
// bool optional
boost::optional<bool> v = pt.get_optional<bool>("test2");
// any type actually
boost::optional<std::string> v2 = pt.get_optional<std::string>("test3");
if (v) // key exists
bool bool_value = v.get();
else // not exists
v.set(false);