UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FJsonObjectConverter Class Reference

#include <JsonObjectConverter.h>

Public Types

using CustomExportCallback = TDelegate< TSharedPtr< FJsonValue >(FProperty *Property, const void *Value)>
 
using CustomImportCallback = TDelegate< bool(const TSharedPtr< FJsonValue > &JsonValue, FProperty *Property, void *Value)>
 

Static Public Member Functions

static JSONUTILITIES_API FString StandardizeCase (const FString &StringIn)
 
static JSONUTILITIES_API bool GetTextFromObject (const TSharedRef< FJsonObject > &Obj, FText &TextOut)
 
static JSONUTILITIES_API bool GetTextFromField (const FString &FieldName, const TSharedPtr< FJsonValue > &FieldValue, FText &TextOut)
 
template<typename InStructType >
static TSharedPtr< FJsonObjectUStructToJsonObject (const InStructType &InStruct, int64 CheckFlags=0, int64 SkipFlags=0, const CustomExportCallback *ExportCb=nullptr)
 
static JSONUTILITIES_API bool UStructToJsonObject (const UStruct *StructDefinition, const void *Struct, TSharedRef< FJsonObject > OutJsonObject, int64 CheckFlags=0, int64 SkipFlags=0, const CustomExportCallback *ExportCb=nullptr, EJsonObjectConversionFlags ConversionFlags=EJsonObjectConversionFlags::None)
 
static JSONUTILITIES_API bool UStructToJsonObjectString (const UStruct *StructDefinition, const void *Struct, FString &OutJsonString, int64 CheckFlags=0, int64 SkipFlags=0, int32 Indent=0, const CustomExportCallback *ExportCb=nullptr, bool bPrettyPrint=true)
 
template<typename InStructType >
static bool UStructToJsonObjectString (const InStructType &InStruct, FString &OutJsonString, int64 CheckFlags=0, int64 SkipFlags=0, int32 Indent=0, const CustomExportCallback *ExportCb=nullptr, bool bPrettyPrint=true)
 
template<typename CharType , template< typename > class PrintPolicy>
static bool UStructToFormattedJsonObjectString (const UStruct *StructDefinition, const void *Struct, FString &OutJsonString, int64 CheckFlags=0, int64 SkipFlags=0, int32 Indent=0, const CustomExportCallback *ExportCb=nullptr, EJsonObjectConversionFlags ConversionFlags=EJsonObjectConversionFlags::None)
 
static JSONUTILITIES_API bool UStructToJsonAttributes (const UStruct *StructDefinition, const void *Struct, TMap< FString, TSharedPtr< FJsonValue > > &OutJsonAttributes, int64 CheckFlags=0, int64 SkipFlags=0, const CustomExportCallback *ExportCb=nullptr, EJsonObjectConversionFlags ConversionFlags=EJsonObjectConversionFlags::None)
 
static JSONUTILITIES_API TSharedPtr< FJsonValueUPropertyToJsonValue (FProperty *Property, const void *Value, int64 CheckFlags=0, int64 SkipFlags=0, const CustomExportCallback *ExportCb=nullptr, FProperty *OuterProperty=nullptr, EJsonObjectConversionFlags ConversionFlags=EJsonObjectConversionFlags::None)
 
static JSONUTILITIES_API bool JsonObjectToUStruct (const TSharedRef< FJsonObject > &JsonObject, const UStruct *StructDefinition, void *OutStruct, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
template<typename OutStructType >
static bool JsonObjectToUStruct (const TSharedRef< FJsonObject > &JsonObject, OutStructType *OutStruct, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
static JSONUTILITIES_API bool JsonAttributesToUStruct (const TMap< FString, TSharedPtr< FJsonValue > > &JsonAttributes, const UStruct *StructDefinition, void *OutStruct, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
static JSONUTILITIES_API bool JsonValueToUProperty (const TSharedPtr< FJsonValue > &JsonValue, FProperty *Property, void *OutValue, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
template<typename OutStructType >
static bool JsonObjectStringToUStruct (const FString &JsonString, OutStructType *OutStruct, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
template<typename OutStructType >
static bool JsonArrayStringToUStruct (const FString &JsonString, TArray< OutStructType > *OutStructArray, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
template<typename OutStructType >
static bool JsonArrayToUStruct (const TArray< TSharedPtr< FJsonValue > > &JsonArray, TArray< OutStructType > *OutStructArray, int64 CheckFlags=0, int64 SkipFlags=0, const bool bStrictMode=false, FText *OutFailReason=nullptr, const CustomImportCallback *ImportCb=nullptr)
 
static JSONUTILITIES_API FFormatNamedArguments ParseTextArgumentsFromJson (const TSharedPtr< const FJsonObject > &JsonObject)
 

Static Public Attributes

static JSONUTILITIES_API const CustomExportCallback ExportCallback_WriteISO8601Dates
 

Detailed Description

Class that handles converting Json objects to and from UStructs

Member Typedef Documentation

◆ CustomExportCallback

Optional callback that will be run when exporting a single property to Json. If this returns a valid value it will be inserted into the export chain. If this returns nullptr or is not bound, it will try generic type-specific export behavior before falling back to outputting ExportText as a string.

◆ CustomImportCallback

Optional callback that will be run when importing a single property from Json. If this returns true, it should have successfully turned the Json value into the property value. If this returns false or is not bound, it will try generic type-specific import behavior before failing.

Member Function Documentation

◆ GetTextFromField()

bool FJsonObjectConverter::GetTextFromField ( const FString &  FieldName,
const TSharedPtr< FJsonValue > &  FieldValue,
FText TextOut 
)
static

Convert a Json value to text (takes some hints from the value name)

◆ GetTextFromObject()

bool FJsonObjectConverter::GetTextFromObject ( const TSharedRef< FJsonObject > &  Obj,
FText TextOut 
)
static

Parse an FText from a json object (assumed to be of the form where keys are culture codes and values are strings)

◆ JsonArrayStringToUStruct()

template<typename OutStructType >
static bool FJsonObjectConverter::JsonArrayStringToUStruct ( const FString &  JsonString,
TArray< OutStructType > *  OutStructArray,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
inlinestatic

Converts from a json string containing an array to an array of UStructs

Parameters
JsonStringString containing JSON formatted data.
OutStructArrayThe UStruct array to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags.
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any properties matched but failed to deserialize.

◆ JsonArrayToUStruct()

template<typename OutStructType >
static bool FJsonObjectConverter::JsonArrayToUStruct ( const TArray< TSharedPtr< FJsonValue > > &  JsonArray,
TArray< OutStructType > *  OutStructArray,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
inlinestatic

Converts from an array of json values to an array of UStructs.

Parameters
JsonArrayArray containing json values to convert.
OutStructArrayThe UStruct array to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags.
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any of the matching elements are not an object, or if one of the matching elements could not be converted to the specified UStruct type.

◆ JsonAttributesToUStruct()

bool FJsonObjectConverter::JsonAttributesToUStruct ( const TMap< FString, TSharedPtr< FJsonValue > > &  JsonAttributes,
const UStruct StructDefinition,
void OutStruct,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
static

Converts a set of json attributes (possibly from within a JsonObject) to a UStruct, using importText

Parameters
JsonAttributesJson Object to copy data out of
StructDefinitionUStruct definition that is looked over for properties
OutStructThe UStruct instance to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any properties matched but failed to deserialize

◆ JsonObjectStringToUStruct()

template<typename OutStructType >
static bool FJsonObjectConverter::JsonObjectStringToUStruct ( const FString &  JsonString,
OutStructType OutStruct,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
inlinestatic

Converts from a json string containing an object to a UStruct

Parameters
JsonStringString containing JSON formatted data.
OutStructThe UStruct instance to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any properties matched but failed to deserialize

◆ JsonObjectToUStruct() [1/2]

bool FJsonObjectConverter::JsonObjectToUStruct ( const TSharedRef< FJsonObject > &  JsonObject,
const UStruct StructDefinition,
void OutStruct,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
static

Converts from a Json Object to a UStruct, using importText

Parameters
JsonObjectJson Object to copy data out of
StructDefinitionUStruct definition that is looked over for properties
OutStructThe UStruct instance to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any properties matched but failed to deserialize

◆ JsonObjectToUStruct() [2/2]

template<typename OutStructType >
static bool FJsonObjectConverter::JsonObjectToUStruct ( const TSharedRef< FJsonObject > &  JsonObject,
OutStructType OutStruct,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
inlinestatic

Templated version of JsonObjectToUStruct

Parameters
JsonObjectJson Object to copy data out of
OutStructThe UStruct instance to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if any properties matched but failed to deserialize

◆ JsonValueToUProperty()

bool FJsonObjectConverter::JsonValueToUProperty ( const TSharedPtr< FJsonValue > &  JsonValue,
FProperty Property,
void OutValue,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const bool  bStrictMode = false,
FText OutFailReason = nullptr,
const CustomImportCallback ImportCb = nullptr 
)
static

Converts a single JsonValue to the corresponding FProperty (this may recurse if the property is a UStruct for instance).

Parameters
JsonValueThe value to assign to this property
PropertyThe FProperty definition of the property we're setting.
OutValuePointer to the property instance to be modified.
CheckFlagsOnly convert sub-properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip sub-properties that match any of these flags
bStrictModeWhether to strictly check the json attributes
OutFailReasonReason of the failure if any
ImportCbOptional callback to override import behaviour, if this returns false it will fallback to the default
Returns
False if the property failed to serialize

◆ ParseTextArgumentsFromJson()

FFormatNamedArguments FJsonObjectConverter::ParseTextArgumentsFromJson ( const TSharedPtr< const FJsonObject > &  JsonObject)
static

◆ StandardizeCase()

FString FJsonObjectConverter::StandardizeCase ( const FString &  StringIn)
static

FName case insensitivity can make the casing of UPROPERTIES unpredictable. Attempt to standardize output.

◆ UPropertyToJsonValue()

TSharedPtr< FJsonValue > FJsonObjectConverter::UPropertyToJsonValue ( FProperty Property,
const void Value,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const CustomExportCallback ExportCb = nullptr,
FProperty OuterProperty = nullptr,
EJsonObjectConversionFlags  ConversionFlags = EJsonObjectConversionFlags::None 
)
static

◆ UStructToFormattedJsonObjectString()

template<typename CharType , template< typename > class PrintPolicy>
static bool FJsonObjectConverter::UStructToFormattedJsonObjectString ( const UStruct StructDefinition,
const void Struct,
FString &  OutJsonString,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
int32  Indent = 0,
const CustomExportCallback ExportCb = nullptr,
EJsonObjectConversionFlags  ConversionFlags = EJsonObjectConversionFlags::None 
)
inlinestatic

Wrapper to UStructToJsonObjectString that allows a print policy to be specified.

◆ UStructToJsonAttributes()

bool FJsonObjectConverter::UStructToJsonAttributes ( const UStruct StructDefinition,
const void Struct,
TMap< FString, TSharedPtr< FJsonValue > > &  OutJsonAttributes,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const CustomExportCallback ExportCb = nullptr,
EJsonObjectConversionFlags  ConversionFlags = EJsonObjectConversionFlags::None 
)
static

Converts from a UStruct to a set of json attributes (possibly from within a JsonObject)

Parameters
StructDefinitionUStruct definition that is looked over for properties
StructThe UStruct instance to copy out of
OutJsonAttributesMap of attributes to copy in to
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
ExportCbOptional callback to override export behavior, if this returns null it will fallback to the default
ConversionFlagsBitwise flags to customize the conversion behavior
Returns
False if any properties failed to write

◆ UStructToJsonObject() [1/2]

template<typename InStructType >
static TSharedPtr< FJsonObject > FJsonObjectConverter::UStructToJsonObject ( const InStructType InStruct,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const CustomExportCallback ExportCb = nullptr 
)
inlinestatic

Templated version of UStructToJsonObject to try and make most of the params. Also serves as an example use case

Parameters
InStructThe UStruct instance to read from
ExportCbOptional callback to override export behavior, if this returns null it will fallback to the default
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
Returns
FJsonObject pointer. Invalid if an error occurred.

◆ UStructToJsonObject() [2/2]

bool FJsonObjectConverter::UStructToJsonObject ( const UStruct StructDefinition,
const void Struct,
TSharedRef< FJsonObject OutJsonObject,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
const CustomExportCallback ExportCb = nullptr,
EJsonObjectConversionFlags  ConversionFlags = EJsonObjectConversionFlags::None 
)
static

Converts from a UStruct to a Json Object, using exportText

Parameters
StructDefinitionUStruct definition that is looked over for properties
StructThe UStruct instance to copy out of
OutJsonObjectJson Object to be filled in with data from the ustruct
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
ExportCbOptional callback to override export behavior, if this returns null it will fallback to the default
ConversionFlagsBitwise flags to customize the conversion behavior
Returns
False if any properties failed to write

◆ UStructToJsonObjectString() [1/2]

template<typename InStructType >
static bool FJsonObjectConverter::UStructToJsonObjectString ( const InStructType InStruct,
FString &  OutJsonString,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
int32  Indent = 0,
const CustomExportCallback ExportCb = nullptr,
bool  bPrettyPrint = true 
)
inlinestatic

Templated version; Converts from a UStruct to a json string containing an object, using exportText

Parameters
InStructThe UStruct instance to copy out of
OutJsonStringJson Object to be filled in with data from the ustruct
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
IndentHow many tabs to add to the json serializer
ExportCbOptional callback to override export behavior, if this returns null it will fallback to the default
bPrettyPrintOption to use pretty print (e.g., adds line endings) or condensed print
Returns
False if any properties failed to write

◆ UStructToJsonObjectString() [2/2]

bool FJsonObjectConverter::UStructToJsonObjectString ( const UStruct StructDefinition,
const void Struct,
FString &  OutJsonString,
int64  CheckFlags = 0,
int64  SkipFlags = 0,
int32  Indent = 0,
const CustomExportCallback ExportCb = nullptr,
bool  bPrettyPrint = true 
)
static

Converts from a UStruct to a json string containing an object, using exportText

Parameters
StructDefinitionUStruct definition that is looked over for properties
StructThe UStruct instance to copy out of
JsonObjectJson Object to be filled in with data from the ustruct
CheckFlagsOnly convert properties that match at least one of these flags. If 0 check all properties.
SkipFlagsSkip properties that match any of these flags
IndentHow many tabs to add to the json serializer
ExportCbOptional callback to override export behavior, if this returns null it will fallback to the default
bPrettyPrintOption to use pretty print (e.g., adds line endings) or condensed print
Returns
False if any properties failed to write

Member Data Documentation

◆ ExportCallback_WriteISO8601Dates

const FJsonObjectConverter::CustomExportCallback FJsonObjectConverter::ExportCallback_WriteISO8601Dates
static
Initial value:
=
FJsonObjectConverter::CustomExportCallback::CreateLambda(
[](FProperty* Prop, const void* Data) -> TSharedPtr<FJsonValue>
{
{
if (StructProperty->Struct->GetFName() == NAME_DateTime)
{
return MakeShared<FJsonValueString>(static_cast<const FDateTime*>(Data)->ToIso8601());
}
}
return {};
})
#define checkSlow(expr)
Definition AssertionMacros.h:332
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition UnrealType.h:174
Definition UnrealType.h:6306
Definition SharedPointer.h:692
Definition DateTime.h:76

The documentation for this class was generated from the following files: