Add JSON functionality to a Plugin

Hey All,

I have been developing a plugin and would like to add JSON functionality into it. I am able to use the FJsonObject, etc. on the project level but not on the plugin level.

I can see the JsonObject.h, JsonSerializer.h, etc. in the ExternalDependencies of the Solution in SolutionExplorer for the project, but this doesn’t allow me to use it in a plugin. This makes sense but is there a way to get the same sort of thing into the plugin?

I can also see the Json and JsonUtilities in the PrivateDependencies when I use it in the project but trying to add that to a plugin doesn’t seem to work. Is there a way to get this to work?

Cheers,
cvolpe

2 Likes

Isn’t the module name “Json” for adding it as a dependency?

3 Likes

Yes, and I put it in as such. Sorry for the error above.

I have adjusted it to reflect “Json” and “JsonUtilities” in the post.

3 Likes

Do you have a snippet of your Build.cs file and the #inlclude you are using for JSON? Also, I had an issue where builds weren’t showing new content properly so try to add the PrivateDependencies again (if you removed them) and then close the project and IDE and generate your solution files again. Then run a build from your IDE and then open the project again.

3 Likes

This is inside my plugin’s Build.cs file:

PrivateDependencyModuleNames.AddRange(
	new string[]
	{
		"CoreUObject",
		"Engine",
		"Slate",
		"SlateCore",
		"Json",
		"JsonUtilities",
	}
);

The error I am getting is that I have an unresolved external symbol (LNK2019).

If I remove the “Json” and “JsonUtilities” from the plugin’s Build.cs I get many more errors due to the JSON code not knowing what to do. So it seems to be a linking issue, but I am not sure how to add that into the plugin itself.

1 Like

If I try to add “Json” and “JsonUtilities” to the project’s Build.cs, it doesn’t seem to matter either.

PrivateDependencyModuleNames.AddRange(
	new string[] {
		"Json",
		"JsonUtilities"
	});
1 Like

Figured out my issue. Appears that I removed a needed override function for the constructor:

UJsonBPLibrary::UJsonBPLibrary(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

Went back and recreated the plugin to see what the difference was. Once I added that back in I was able to build successfully. So the way I have the “Json” and “JsonUtilities” in the Build.cs was just fine, it was just this issue that caused the LNK2019 issue, I believe.

2 Likes