How to parse an Array of FJsonValue to FString

So I’m trying to figure out how to pass a JSON object to the a browser inside of UE.

Essentially I have a slate browser that I bind a UObject class to (using BindUObject), and I’m trying to pass a member of the class into the browser so that I can access it on the JavaScript side.

My current approach:

FString UCustomClass::GetJsonString()
{
	FString TempString;

	for (TSharedPtr<FJsonValue> JSON : FExternalClass::GetJSONData())
	{
		UE_LOG(LogTemp, Error, TEXT("%s"), *JSON->AsString());
		TempString.Append(JSON->AsString());
	}

	return JSONString = TempString;
}

This doesnt work, and gives this error in the Output Log when I try to print the string for Debugging:
LogJson: Error: Json Value of type 'Object' used as a 'String'.


Is there any actual way to take an TArray<TSharedPtr<FJsonValue>> and make it into an FString?

I would really appreciate any help, as I’m completely lost on how to proceed with this?

Use FJsonSerializer utilities to parse/write json :

#include "Serialization/JsonSerializer.h"

//TArray<TSharedPtr<FJsonValue>> Data;
FString Result;
auto Writer = TJsonWriterFactory<>::Create(&Result);
if (FJsonSerializer::Serialize(Data, Writer))
{
    UE_LOG(LogTemp, Log, TEXT("JSON: %s"), *Result);
}
1 Like

Hey, thanks for the reply!
This worked quite well!