Property names are changed by UStructToJsonObjectString

Hi, there:
I’m trying Json-Request-Response in C++, and I use FJsonObjectConverter::UStructToJsonObjectString to convert a struct to a string, and found this api has an issue.
this is my struct:

42184-struct.png

this is my code:

after conversion, the json string becomes:

the member variable “UserAccount” becomes “userAccount”,
“GUID” becomes “gUId”, and “Password” becomes “password”.

Cause I convert this string to struct in server by Java, the Json library in Java can’t identify the struct if the case of member variable’s name doesn’t match.

Any advice will be thankful.

If I were to through a guess at this, I would assume it is because UE4 tries to adhere to variable naming conventions of camelCase, which for many programming languages starts with a lowercase (not with standing PascalCase, which starts with uppercase) and capitalizes the first letter of each word after. As in the case of UserAccount, in javascript for instance, the convention would be “userAccount”. It is worth noting that JSON does stand for javaScriptObjectNotation.

I am not sure if I would agree with UE4 forcing conventions on coders, and I could be completely wrong.

You probably just need to adjust for the lowercase letters on the receiver.

Hey ZenTech-

It appears that the function FJsonObjectConverter::StandardizeCase() is converting the first character from uppercase to lowercase. If you’re using a source version of the engine, changing the FJsonObjectConverter::UStructToJsonAttributes() function from FString VariableName = StandardizeCase(Property->GetName()); to FString VariableName = Property->GetName(); then it should match the name of the UPROPERTY on the struct after the conversion.

Cheers

1 Like