summaryrefslogtreecommitdiff
path: root/AK/JsonValue.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-24 12:03:31 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-24 12:03:31 +0200
commit8392c549a3f8af09fce0218b680f766f593aaf3a (patch)
treeb4c485a1af35335984dd1bd262b450f8f554ff0e /AK/JsonValue.h
parentdd36f797d5ad2bf16580a9d03914714ee2e0dd0e (diff)
downloadserenity-8392c549a3f8af09fce0218b680f766f593aaf3a.zip
JsonValue: Add as_array() and as_object().
Diffstat (limited to 'AK/JsonValue.h')
-rw-r--r--AK/JsonValue.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/AK/JsonValue.h b/AK/JsonValue.h
index 439429d9d7..f842014d6f 100644
--- a/AK/JsonValue.h
+++ b/AK/JsonValue.h
@@ -46,9 +46,20 @@ public:
String as_string() const
{
- if (m_type == Type::String)
- return *m_value.as_string;
- return { };
+ ASSERT(is_string());
+ return *m_value.as_string;
+ }
+
+ const JsonObject& as_object() const
+ {
+ ASSERT(is_object());
+ return *m_value.as_object;
+ }
+
+ const JsonArray& as_array() const
+ {
+ ASSERT(is_array());
+ return *m_value.as_array;
}
Type type() const { return m_type; }