diff --git a/lib/json.cpp b/lib/json.cpp index 4f60747e..6e454cf4 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -295,6 +295,20 @@ JSON::Value::operator bool(){ return false;//unimplemented? should never happen... } +/// Explicit conversion to std::string. +const std::string JSON::Value::asString(){ + return (std::string)*this; +} +/// Explicit conversion to long long int. +const long long int JSON::Value::asInt(){ + return (long long int)*this; +} +/// Explicit conversion to bool. +const bool JSON::Value::asBool(){ + return (bool)*this; +} + + /// Retrieves or sets the JSON::Value at this position in the object. /// Converts destructively to object if not already an object. JSON::Value & JSON::Value::operator[](const std::string i){ diff --git a/lib/json.h b/lib/json.h index 3c01ae02..dc35dfcb 100644 --- a/lib/json.h +++ b/lib/json.h @@ -51,6 +51,9 @@ namespace JSON{ operator long long int(); operator std::string(); operator bool(); + const std::string asString(); + const long long int asInt(); + const bool asBool(); //array operator for maps and arrays Value & operator[](const std::string i); Value & operator[](const char * i);