diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 19:47:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 19:47:35 +0200 |
commit | 04a8fc9bd7d4a3dd31cce39266464bb05ca0bfca (patch) | |
tree | d0e7d113138caffe0f56ef19b4814193cc4cc3ec /AK/JsonObject.cpp | |
parent | 7ccb84e58efd4b48ec51150a5d8495bad71bbfbc (diff) | |
download | serenity-04a8fc9bd7d4a3dd31cce39266464bb05ca0bfca.zip |
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.
Diffstat (limited to 'AK/JsonObject.cpp')
-rw-r--r-- | AK/JsonObject.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/AK/JsonObject.cpp b/AK/JsonObject.cpp new file mode 100644 index 0000000000..11f01bd235 --- /dev/null +++ b/AK/JsonObject.cpp @@ -0,0 +1,21 @@ +#include <AK/JsonObject.h> +#include <AK/StringBuilder.h> + +String JsonObject::to_string() const +{ + StringBuilder builder; + int index = 0; + builder.append('{'); + for_each_member([&] (auto& key, auto& value) { + builder.append('"'); + builder.append(key); + builder.append('"'); + builder.append(':'); + builder.append(value.to_string()); + if (index != size() - 1) + builder.append(','); + ++index; + }); + builder.append('}'); + return builder.to_string(); +} |