Util: Add JSON accessors

This commit is contained in:
Riyyi
2022-06-16 11:38:22 +02:00
parent 5188d57d19
commit c385432bb0
5 changed files with 23 additions and 2 deletions
+13
View File
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
*/
#include <cassert> // assert
#include <string>
#include <utility> // move
@@ -64,6 +65,18 @@ Value::Value(const Object& value)
m_value.asObject = new Object(value);
}
Value Value::operator[](size_t index)
{
assert(m_type == Type::Array);
return m_value.asArray->values().at(index);
}
Value Value::operator[](const std::string& key)
{
assert(m_type == Type::Object);
return m_value.asObject->members().at(key);
}
// ------------------------------------------
void Value::clear()