diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index 92893040d6..b56780bd87 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -110,6 +110,11 @@ JsonValue::JsonValue(const String& value) } } +JsonValue::JsonValue(const IPv4Address& value) + : JsonValue(value.to_string()) +{ +} + JsonValue::JsonValue(const JsonObject& value) : m_type(Type::Object) { diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 49eda29aed..c220924009 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include namespace AK { @@ -44,6 +46,7 @@ public: JsonValue(bool); JsonValue(const char*); JsonValue(const String&); + JsonValue(const IPv4Address&); JsonValue(const JsonArray&); JsonValue(const JsonObject&); @@ -57,6 +60,13 @@ public: return default_value; } + Optional to_ipv4_address() const + { + if (!is_string()) + return {}; + return IPv4Address::from_string(as_string()); + } + int as_int() const { ASSERT(is_int());