JsonUtility in Unity not deserializing certain fields from JSON

I'm trying to deserialize a JSON string into a Unity struct using JsonUtility.FromJson(), but certain fields like description, name, thumbnailAddress, and imageAddress always come out as null. Other fields are deserialized correctly.

This is the function I use to fetch the configs from unity gaming services:

void GetConfigValues()
{
    string shopCategoriesConfigJson = RemoteConfigService.Instance.appConfig.GetJson("VIRTUALSHOP_CONFIG_BASIC_02");
    Debug.Log("raw json:"+shopCategoriesConfigJson.ToString());
    virtualShopConfig = JsonUtility.FromJson<VirtualShopConfig>(shopCategoriesConfigJson);
    Debug.Log(virtualShopConfig.ToString());
}

This is one line of the raw json:

category:"TabType.TabTypes.candles", enabled:True, items: id:"VIRTUALSHOP_5_ANCIENTARCANE_FOR_AMIRITE" name:"" description:""thumbnailAddress:""imageAddress:""SizeType:_256x256, Style:natural, Currency:currencyTest1, ObjectType:cardSkin, Price:0, Level:0, TabType:favorites, TabSubGroup:staticTabs, TimeLimited:False

Here's the struct I'm trying to deserialize into:

[Serializable]
public struct ItemConfig
{
    public string id;
    public string name;
    public string description;
    public string thumbnailAddress; // addressableManager has the sprite
    public string imageAddress;     // addressableManager has the sprite
    // ... [other fields] ...
}
And here's a sample of the JSON I'm trying to deserialize:
{
    "currency": 0,
    "description": "Beautiful Amirite test",
    "imageAddress": "Assets/Models/Items/Sprites/amirite_256x256.png",
    "level": 0,
    "name": "Amirite",
    "objectType": 1,
    "price": 5,
    "sizeType": 0,
    "style": 0,
    "tabSubGroup": 2,
    "tabType": 3,
    "thumbnailAddress": "Assets/Models/Items/Sprites/amirite_256x256.png",
    "timeLimited": "yes"
}

Some observations:

1- timeLimited field is a boolean. I wrote "no" in the json but the result is False. There is some sort of conversion?

2- the id:"VIRTUALSHOP_5_ANCIENTARCANE_FOR_AMIRITE" is the ID from the virtual purchase that links a currency and the item. So its not the id of the item here however, it fetch correctly some values that are included in the item json only such as tabType, price, etc.

3- The only issues are with the 4 strings. The rest is fine.

p.s: also posted this on stackoverflow https://stackoverflow.com/posts/77240008/edit

That raw json has syntax errors. For example "items: id:" is not correct, opening brackets are missing there.

timeLimited in the json is a string "yes" and not a bool, as denoted by the quotation marks. Actual bools are printed as either true or false without quotation.

1 Like

Yes you are right. I need to fix this.

I found a temporary fix by moving the location of the field name, imageAddress and thumbnailAddress and now it works. Instead of having them in the Inventory Item Json, I added them to the remoteConfig Json. Its not what I want but its working for now.