JSON file returns empty values in packaged build

Hi,
I’m using Unreal Engine 5.5’s built-in JSON plugin to read a local JSON file. The JSON file contains a structure.
Everything works fine in-editor. The file is read correctly, and the values are displayed on screen. However, after packaging my project, the JSON file always returns the default/empty values of my structure instead of the actual contents.

Has anyone encountered this issue before?

Is the json file present physically in the packed build? It might not be packed by default.

I’m reading from a file. It’s a file located in the user directory.

With my project, the json file is not included in the packaged build. It’s a seperate file from the project.

In-editor and in the packaged build, the file in question is the exact same file located in the user directory. Only for some reason in the packaged build, it returns default values even tho the success bool says success and even tho the in-editor version reads the local file with no problems.

It could be a matter of file permissions. The editor has elevated status in regards to file access compared to the packaged game.

For a test try moving the file to a non protected folder and see if it works.

Even in a non-protected folder it doesn’t read the file correct.
Saving does work correctly, even if the json file is in a protected folder.

Blueprint function library to get user path

File in: C:\Users\YourName\AppData

image

File internals

In packed project

doe

Works in packed version no problem.

And in shipping added a quick widget for tests as print string is stripped.

Shows up no problems

Double check your filename. Maybe you have an extra space at the end or something that is throwing off the engine. Check if the json is also valid via json lint.

I found out that he reads everything in the json file correctly, except for arrays.
For some reason arrays will always have their default value parsed thru in the packaged build.

Do arrays have this issue with you too?

I checked if my json is valid, and it’s valid.

code to de-serialize json with arrays (where UPathLibrary is the library, replace with own class name)


TMap<FString, FString> UPathLibrary::DeSerializeJsonContent(const FString& JsonContent)
{
	TMap<FString, FString> ReturnMap;

	TSharedPtr<FJsonObject> JsonObject;
	TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonContent);

	if (FJsonSerializer::Deserialize(Reader, JsonObject) && JsonObject.IsValid())
	{
		for (const TPair<FString, TSharedPtr<FJsonValue>>& Pair : JsonObject->Values)
		{
			CheckJsonType(Pair, &ReturnMap);
		}
	}
	return ReturnMap;
}

void UPathLibrary::CheckJsonType(TPair<FString, TSharedPtr<FJsonValue>> Json, TMap<FString, FString>* Map)
{
	if (Json.Value->Type == EJson::Object || Json.Value->Type == EJson::Array)
	{
		if (Json.Value->Type == EJson::Object)
		{
			for (const TPair<FString, TSharedPtr<FJsonValue>>& Pair : Json.Value->AsObject()->Values)
			{
				CheckJsonType(Pair, Map);
			}
		}
		else if (Json.Value->Type == EJson::Array)
		{
			int32 Index = 1;
			for (const auto& ArrayValue : Json.Value->AsArray())
			{
				Map->Add(Json.Key + "_" + FString::FromInt(Index), ArrayValue->AsString());
				Index++;
			}
		}
	}
	else
	{
		Map->Add(Json.Key, Json.Value->AsString());
	}
}

You need to add module “Json” to the build file

based on post

You could also go the route of using FJsonObjectConverter::JsonObjectStringToUStruct

image
Our arrays look different from each other. My array looks more in the lines of the image attached.

image

Result with the following json

simplified

The mapping function would just need to be rebuilt to support arrays as values so that it doesn’t create an incremented key.

But nonetheless it does register the array as a value and display it.

Though if you know the targeted outcome structure, I would strongly suggest using the inbuilt engine function to convert it to a targeted ustruct.