1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

AK: Add some classes for JSON encoding.

This patch adds JsonValue, JsonObject and JsonArray. You can use them to
build up a JsonObject and then serialize it to a string via to_string().

This patch only implements encoding, no decoding yet.
This commit is contained in:
Andreas Kling 2019-06-17 19:47:35 +02:00
parent 7ccb84e58e
commit 04a8fc9bd7
7 changed files with 301 additions and 0 deletions

24
AK/JsonArray.h Normal file
View file

@ -0,0 +1,24 @@
#pragma once
#include <AK/JsonValue.h>
#include <AK/Vector.h>
class JsonArray {
public:
JsonArray() {}
~JsonArray() {}
int size() const { return m_values.size(); }
bool is_empty() const { return m_values.is_empty(); }
const JsonValue& at(int index) const { return m_values.at(index); }
const JsonValue& operator[](int index) const { return at(index); }
void clear() { m_values.clear(); }
void append(const JsonValue& value) { m_values.append(value); }
String to_string() const;
private:
Vector<JsonValue> m_values;
};