Convert TArray to json string

For reference, if anybody is interested, of course you can serialize without a root object. I you skip the root object part of the code and directly use the TArray of FJsonValueString objects as an argument for the serialization, it will produce: [“Test”, “Test2”]

The code becomes:

TArray<TSharedPtr<FJsonValue>> items;
items.Add(MakeShareable(new FJsonValueString("Test")));
items.Add(MakeShareable(new FJsonValueString("Test2")));

FString OutputString;
TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
FJsonSerializer::Serialize(items, Writer);
1 Like