How to stop case correction when converting from Struct to JSON in Packaged Build?

Have a custom struct I’m trying to convert to JSON. It successfully converts to JSON with the correct capitalization (matching the variable names of the struct) in the editor, but the capitalization on the variable names gets corrected in a packaged build, which messes up the API I’m using.

For example, the struct variable name is “userID”, which is what the API expects, but when I use the UE4 methods to serialize the struct into JSON the variable name becomes “UserId” which makes the JSON object not work with the API.

I found in the JsonObjectConverter::UStructToJsonAttributes that there’s a line that calls
StandarizeCase(Property->GetName()), so I made a custom version of this function and removed this line but it didn’t solve the problem. In fact, I traced the problem through debugging to when it begins iterating through the uproperties of the struct. It seems to think the variable names are capitalized a different way from the start of iteration when passed the ustruct type.

Furthermore, it doesn’t capitalize all variable names. Here are some of the variable names and what they print out as in a packaged build (all names are correct in-editor):

  • var name → becomes this
  • userID → UserId
  • sessionID → SessionId
  • eventName → EventName
  • eventTimestamp → eventTimestamp (no change)
  • eventParams → eventParams (no change)

Also, names inside the tmap called “eventParams” don’t seem to change. I send the events to the API and can confirm that there’s no issue with misprinting to the console as the API confirms the names have changed as listed above.

I’m highly suspicious of the FNames assigned to these variables. I believe the FNames are saved somewhere as “UserId” for example and even though I changed it to “userID” in code. According to this question Fnames became case sensitive in 4.5 which in theory should be good but I’m not seeing the change reflected.

I’ve tried completely removing the struct and all functions related to it, deleting the Intermediate and Saved folders, and rebuilding and packaging without the struct, then adding them back in but the fnames seem to still be retained!

I’m currently building a struct to JSON converter from scratch to avoid this issue, but figured I’d ask to see if anybody else has had this issue or knows if I’m doing something wrong or how to get around it. Again, the whole thing works as-is in editor and standalone, just packaged builds are the problem. Any help is greatly appreciated.

Here is my struct:

USTRUCT()
struct FDelta_Event {
	GENERATED_BODY()
	UPROPERTY() FString eventName;
	UPROPERTY() FString userID;	
	UPROPERTY() FString sessionID;	
	UPROPERTY() FString eventTimestamp;						
	UPROPERTY() TMap<FString, FString> eventParams;

	FDelta_Event() {
		FDateTime currentTime = FDateTime::Now();
// manually convert currentTime into API format Format: yyyy-MM-dd HH:mm:ss.SSS
// with a bunch of ifs and eventTimestamp.AppendInt()s

		if ( PLATFORM_WINDOWS )
		{
			eventParams.Add( "platform", "WINDOWS_DESKTOP" );
		}
		else if ( PLATFORM_XBOXONE )
		{
			eventParams.Add( "platform", "XBOXONE" );
		}
		else
		{
			eventParams.Add( "platform", "UNKNOWN" );
		}
		eventParams.Add( "sdkVersion", "CustomSDK" );
	}
};

Here is the the templated function I would like to call:

template <typename StructType>
void UHttpService::GetJsonStringFromStruct( StructType filledStruct, FString& stringOutput )
{
	UStructToJsonObjectString( StructType::StaticStruct(), &filledStruct, stringOutput, 0, 0 );
}
2 Likes

Hello,

did you find any solution? I have same problem.

1 Like

Has anyone resolved this? This is a big issue

1 Like

FName is only case-sensitive in the editor, and this is by design (See: NameTypes.h) All FNames use lower-case strings in packaged builds by default. You can force this off, but this is global and not recommended.

Generally if you need case-sensitive text, you should use FString instead.

1 Like

So what would you recommend doing for “How to stop case correction when converting from Struct to JSON” using FJsonObjectConverter::UStructToJsonObjectString? In my case I have a
FString playerUID in my struct that becomes playerUId when serialized.

I also encountered this problem, and I now think of two ways:

  1. if the field is a more specific name, replace it directly with an FString lookup;
  2. or refactoring a UStructToJsonObject () this function.

Did guys have a better solution?