ladybird/AK/JsonObject.cpp
Andreas Kling aa3df518e7 AK: Rename JsonObject::to_string() and pals to serialized().
And the variant that serializes into a StringBuilder is called serialize().
2019-06-18 09:37:47 +02:00

31 lines
625 B
C++

#include <AK/JsonObject.h>
#include <AK/StringBuilder.h>
namespace AK {
void JsonObject::serialize(StringBuilder& builder) const
{
int index = 0;
builder.append('{');
for_each_member([&] (auto& key, auto& value) {
builder.append('"');
builder.append(key);
builder.append('"');
builder.append(':');
value.serialize(builder);
if (index != size() - 1)
builder.append(',');
++index;
});
builder.append('}');
}
String JsonObject::serialized() const
{
StringBuilder builder;
serialize(builder);
return builder.to_string();
}
}