# How do I properly utilize JsonObjectStringToUStruct?

**URL:** <https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907>\
**Category:** Editor Scripting\
**Tags:** Struct, ustruct, unreal-engine, json, CPP, question\
**Created:** [March 29, 2014, 5:40am UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907 "2014-03-29T05:40:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheAggie](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheAggie](https://forums.unrealengine.com/u/TheAggie)\
**Post date:** [March 29, 2014, 5:40am UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/1 "2014-03-29T05:40:46Z")

</div>

I’m trying to take an object from a json http response and convert it to a UStruct. I came across the JsonObjectStringToUStruct function via JsonUtilities.h. While it looks like the solution to my problem, I’m having some issues with it. I haven’t worked in c++ in forever, so please forgive me for any syntax issues. Anyway, I’m not exactly sure how to properly supply the parameters needed by this procedure. Specifically the structure definition UStruct. I’m assuming this is for mapping parameters from json into the corresponding properties of the output struct, but I’m not sure what that is supposed to look like.

Any help would be greatly appreciated. Here is the basics of what I have so far.

```
const UStruct *structDefinition = {
    // What do I do with this.. if anything? 
    		};
 
    FTestObjectStruct testObjectStructOut = FTestObjectStruct();
    
    bool bSomePropertiesWereWritten = FJsonObjectConverter::JsonObjectStringToUStruct(jsonResponseString, structDefinition, &testObjectStructOut, 0, 0);
```

---

<div class="post-metadata">

**Author:** ![TheAggie](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheAggie](https://forums.unrealengine.com/u/TheAggie)\
**Post date:** [March 30, 2014, 1:42am UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/2 "2014-03-30T01:42:58Z")

</div>

bump. Still stuck. Any suggestions.

---

<div class="post-metadata">

**Author:** ![\_Epic\_Ben\_Zeigler](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_Epic\_Ben\_Zeigler](https://forums.unrealengine.com/u/_Epic_Ben_Zeigler)\
**Post date:** [March 31, 2014, 6:47pm UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/3 "2014-03-31T18:47:18Z")

</div>

The part you’re missing is that the struct definition is a UStruct\* object, which is generated as part of the automatic code generation you get when you declare something as USTRUCT in a header file. Here’s an example of a UStruct definition from one of out header files

```
USTRUCT()
struct FNotificationLevelUp
{
	GENERATED_USTRUCT_BODY()

	/** The new level */
	UPROPERTY()
	int32 Level;
    
	FNotificationLevelUp()
		: Level(-1)
	{
	}
};

```

And here’s a simple example of how to use this, where we are converting a json string into a UStruct that’s allocated on the stack:

```
FNotificationLevelUp LevelUpData;
FJsonObjectConverter::JsonObjectStringToUStruct(JsonStr, LevelUpData.StaticStruct(), &LevelUpData, 0, 0)

```

In both examples the important part is that the field names of the UStruct match the names of the json parameters. Our JSON is using java case conventions but UProperties are case insensitive so there’s some hacky code to convert field name case.

---

<div class="post-metadata">

**Author:** ![TheAggie](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheAggie](https://forums.unrealengine.com/u/TheAggie)\
**Post date:** [March 31, 2014, 9:29pm UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/4 "2014-03-31T21:29:40Z")

</div>

Thank you very much Ben, that worked like a charm. I had everything setup correctly but wasn’t aware of the StaticStruct function. I can’t believe I didn’t notice it w/ Intellitype. I was soooooo close. Thanks again!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_741503d3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_741503d3](https://forums.unrealengine.com/u/anonymous_user_741503d3)\
**Post date:** [June 22, 2015, 12:26pm UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/5 "2015-06-22T12:26:40Z")

</div>

This SHOULD be in the docs! StaticStruct() is a kind of a ‘secret knowledge’ as it is now. Thank you, Ben!

---

<div class="post-metadata">

**Author:** ![AlexQuevillon](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexquevillon/32/751975_2.png) [@AlexQuevillon](https://forums.unrealengine.com/u/AlexQuevillon)\
**Post date:** [October 19, 2023, 10:46am UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/6 "2023-10-19T10:46:37Z")

</div>

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/c/d2c78c2a4352506e99031c0d7701b1a908238da0.jpeg "UE5 C++ 2 - How To Read and Write Json Files with C++? - Unreal Engine Tutorial Editor CPP") ](https://www.youtube.com/watch?v=4wJ45mrzrkM&t=372s)

---

<div class="post-metadata">

**Author:** ![kahshmick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kahshmick/32/894879_2.png) [@kahshmick](https://forums.unrealengine.com/u/kahshmick)\
**Post date:** [February 7, 2024, 8:35pm UTC](https://forums.unrealengine.com/t/how-do-i-properly-utilize-jsonobjectstringtoustruct/278907/7 "2024-02-07T20:35:55Z")

</div>

It seems like the above code no longer works in 2024. Instead I need to give the function template parameter like below.

```auto
FNotificationLevelUp LevelUpData;
FJsonObjectConverter::JsonObjectStringToUStruct<FNotificationLevelUp>(JsonStr, &messageObject)

```
