From 45921328e4923a49870f6bd770da3bbbc3b60777 Mon Sep 17 00:00:00 2001 From: Emanuel Sprung Date: Sat, 14 Mar 2020 15:55:06 +0100 Subject: [PATCH] AK: Add get_or() method to JsonObject This allows to retrieve a default value for items thare are not available in the json object. --- AK/JsonObject.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/JsonObject.h b/AK/JsonObject.h index f6d17a4d226..4c50d09c483 100644 --- a/AK/JsonObject.h +++ b/AK/JsonObject.h @@ -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);