JSON Deserialization issues | Dealing with difficult keys like "+/-" and "s%"

Hello Unity community!

I’m working with a third party dataset for a project and am loading the data into my app via JSON like so:

string basepath = “Data/” + TEAM_PREF + “_stats”;
TextAsset t = (TextAsset) Resources.Load( basepath, typeof(TextAsset));
string statsAsJson = t.text;
Stats loadedStats = JsonUtility.FromJson (statsAsJson);

This works great for the most part, but some of my JSON keys look like:
“s+p”
“s%”
“+/-”
which obviously can’t be the names of fields in my Serializable object.

Can anyone recommend a workaround for parsing keys like this with JsonUtility or is my only option to pre-process and rename the keys?

in the meantime, for anyone else who encounters this issue, the pre-process approach turn out to not be that much trouble. use the @ symbol to declare the string as a literal and rename the key before you serialize:

string key1 = @“s+p”;
string key2 = @“s%”;
string key3 = @“+/-”;
statsAsJson = statsAsJson.Replace (key1, “s_and_p”);
statsAsJson= statsAsJson.Replace (key2, “s_perc”);
statsAsJson = statsAsJson.Replace (key3, “plus_minus”);
Stats loadedStats = JsonUtility.FromJson (statsAsJson);