AK: Add get_or() method to JsonObject

This allows to retrieve a default value for items thare are not
available in the json object.
This commit is contained in:
Emanuel Sprung 2020-03-14 15:55:06 +01:00 committed by Andreas Kling
parent 5f579904c1
commit 45921328e4

View file

@ -72,6 +72,12 @@ public:
return value ? *value : JsonValue(JsonValue::Type::Undefined);
}
JsonValue get_or(const String& key, JsonValue alternative) const
{
auto* value = get_ptr(key);
return value ? *value : alternative;
}
const JsonValue* get_ptr(const String& key) const
{
auto it = m_members.find(key);