Quick answer: JsonUtility.FromJson throws ArgumentException: JSON parse error when the string is not a JSON object it can read. Log the string’s length and its first characters before parsing. A leading < is an HTML page from a server, an invisible first character is a UTF-8 byte order mark, a leading [ is a top-level array that needs a wrapper class, and text that stops halfway is a truncated save file. Wrap the call in try/catch, keep the bad file, and fall back to a backup or defaults.

The line that fails is always the same, JsonUtility.FromJson<T>(json), and the Console adds a short phrase after “JSON parse error”. That phrase is the parser telling you what it found at the point where it gave up, and together with the first few characters of the string it identifies the cause. This guide lists the variants and what each one means, then gives code for the four places bad JSON comes from: your own save files, a web server, a top-level array, and a file edited by hand.

The exact error

ArgumentException: JSON parse error: Invalid value.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <...>:0)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <...>:0)
SaveSystem.Load () (at Assets/Scripts/SaveSystem.cs:42)

The text after JSON parse error: changes with the fault. Where this page shows <...>, Unity prints a hex id that can be ignored. The related message for JSON that is valid but has the wrong shape has no “parse error” in it:

ArgumentException: JSON must represent an object type.

FromJsonOverwrite throws the same errors. They are ordinary managed exceptions, so they can be caught, and they occur in the editor and in every kind of build.

What each variant means

MessageWhat the parser foundTypical cause
JSON parse error: Invalid value.A character that cannot start a JSON valueAn HTML page (<!DOCTYPE html>), a byte order mark before the {, plain text such as Not Found, a single-quoted value, True or None from a Python script, a trailing comma in an array
JSON parse error: Missing a name for object member.Something other than a double-quoted name after { or ,A trailing comma before }, single-quoted keys ({'hp':5}), unquoted keys ({hp:5}), a comment
JSON parse error: Missing a comma or '}' after an object member.The object did not continue or closeA file cut off partway, or a comma missing between two members
JSON parse error: Missing a comma or ']' after an array element.The array did not continue or closeA file cut off inside a list
JSON parse error: Missing a closing quotation mark in string.The text ended inside a stringA file cut off in the middle of a value
JSON parse error: The document is empty.Nothing but whitespaceA string of only spaces or line breaks. A save file left full of zero bytes by a crash or power cut during a write can report this too.
JSON parse error: The document root must not follow by other values.A complete JSON value, then more textTwo objects in one file because new data was appended, or leftovers from a longer file that was overwritten without being truncated
JSON must represent an object type.Valid JSON whose top level is not { }A top-level array ([...]), or a bare string or number

The wording of the root message is the parser’s own. Newer versions of the same parser spell it “must not be followed by other values”, so you may see either form. The parser has a few more messages on the same pattern, for example for a missing colon, or for a backslash that does not start a valid escape, which is what a Windows path typed as "C:\Users\me" in a hand-written file produces.

The case that does not throw

An empty string is not on that list. JsonUtility.FromJson returns null for a null or empty string and raises nothing. That is what happens with PlayerPrefs.GetString("save") when the key was never written, since its default is an empty string. The failure then appears one line later as a NullReferenceException on the object you thought you had loaded. A missing file is different again: File.ReadAllText throws FileNotFoundException before any parsing starts.

How to find which cause is yours

Log the string before you parse it. Three facts are enough: the length, the first character as a code point, and the first stretch of text.

if (string.IsNullOrEmpty(json))
{
    Debug.Log("JSON is null or empty");
}
else
{
    string head = json.Length > 80 ? json.Substring(0, 80) : json;
    string tail = json.Length > 40 ? json.Substring(json.Length - 40) : json;
    Debug.Log($"JSON length={json.Length} first=U+{(int)json[0]:X4} head=[{head}] tail=[{tail}]");
}
What the log showsCauseGo to
first=U+FEFFByte order markFix 1
first=U+003C (<), head is HTMLThe server sent a page, not dataFix 2
first=U+005B ([)Top-level arrayFix 3
Head is fine, tail does not end with }Truncated fileFix 4
Tail has text after the final }Appended or overwritten fileFix 4
first=U+0000, or the head is blankZero-filled or blank fileFix 4
Head and tail look rightA syntax slip inside: trailing comma, single quotes, a commentPaste the text into any JSON validator

Fix 1: parse through one guarded method, and strip the BOM

Every FromJson call on data that comes from disk or the network should be able to fail without taking the game down. Put the checks in one place:

using UnityEngine;

public static class JsonSafe
{
    public static bool TryFromJson<T>(string json, out T result) where T : class
    {
        result = null;
        if (string.IsNullOrWhiteSpace(json))
            return false;

        // A UTF-8 byte order mark arrives as U+FEFF. JsonUtility rejects it.
        if (json[0] == '\uFEFF')
            json = json.Substring(1);

        try
        {
            result = JsonUtility.FromJson<T>(json);
        }
        catch (System.ArgumentException e)
        {
            Debug.LogWarning($"JSON rejected: {e.Message} (length {json.Length})");
            return false;
        }
        return result != null;
    }
}

A byte order mark (BOM) is three bytes, EF BB BF, that some editors put at the start of a file saved as “UTF-8 with BOM”. Whether it reaches the parser depends on how you read the file. File.ReadAllText detects and removes it. Encoding.UTF8.GetString(bytes) keeps it as the character U+FEFF, and a response body from a server can carry it as well. Unity’s issue tracker lists the resulting parse error as by design, so the stripping is your job.

When you write JSON yourself, File.WriteAllText(path, json) with no encoding argument writes UTF-8 without a BOM. Passing Encoding.UTF8 as a third argument adds one.

Fix 2: check the response before parsing it

A web server answers with HTML far more often than you expect: a 404 page, a 500 page from the framework, a maintenance notice, a login page from hotel or airport Wi-Fi. The body starts with <, and the parser reports Invalid value.

// Broken: parses whatever came back
yield return request.SendWebRequest();
var config = JsonUtility.FromJson<RemoteConfig>(request.downloadHandler.text);
// Fixed
IEnumerator FetchConfig(string url)
{
    using (UnityWebRequest request = UnityWebRequest.Get(url))
    {
        yield return request.SendWebRequest();

        if (request.result != UnityWebRequest.Result.Success)
        {
            Debug.LogWarning($"Config request failed: {request.responseCode} {request.error}");
            yield break;
        }

        string body = request.downloadHandler.text;
        if (!JsonSafe.TryFromJson(body, out RemoteConfig config))
        {
            string head = body.Length > 120 ? body.Substring(0, 120) : body;
            Debug.LogWarning($"Config was not JSON. Status {request.responseCode}, starts with: {head}");
            yield break;
        }

        Apply(config);
    }
}

The first check catches connection failures and HTTP error codes. The second catches a page that arrives with status 200, which is what a captive portal sends. In both cases keep the game running on the values it already has. A request that never reaches the server fails earlier, with errors such as the one in How to Fix “Curl error 6: Could not resolve host” in UnityWebRequest.

Fix 3: wrap a top-level array

JsonUtility only reads an object at the top level. An API that returns a list gives you JSON must represent an object type.

// Server returns: [{"name":"Ada","score":120},{"name":"Lin","score":95}]

// Broken
ScoreEntry[] scores = JsonUtility.FromJson<ScoreEntry[]>(json);

Wrap the text in an object and parse into a class with one array field:

using UnityEngine;

public static class JsonArray
{
    [System.Serializable]
    private class Wrapper<T>
    {
        public T[] items;
    }

    public static T[] Parse<T>(string json)
    {
        Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>("{\"items\":" + json + "}");
        return wrapper != null ? wrapper.items : null;
    }
}

// Usage
ScoreEntry[] scores = JsonArray.Parse<ScoreEntry>(json);

ScoreEntry needs the [System.Serializable] attribute and public fields named name and score. The same wrapper works in the other direction: put your array in the items field of a small serializable class before calling ToJson, because passing an array straight to ToJson is not supported either.

Fix 4: write saves so a crash cannot truncate them

File.WriteAllText(path, json) empties the file and then fills it. If the game crashes, is force-closed or loses power in between, the player is left with half a file, and the next launch fails with one of the “Missing a comma”, “Missing a closing quotation mark” or “document is empty” variants. Write the new data to a second file, and replace the real one only after the write has finished:

using System.IO;
using System.Text;
using UnityEngine;

public static class SaveFile
{
    public static void Save(string path, SaveData data)
    {
        string tmp = path + ".tmp";
        string bak = path + ".bak";
        byte[] bytes = new UTF8Encoding(false).GetBytes(JsonUtility.ToJson(data));

        // 1. Write the whole new file under a temporary name
        using (FileStream fs = new FileStream(tmp, FileMode.Create, FileAccess.Write, FileShare.None))
        {
            fs.Write(bytes, 0, bytes.Length);
            fs.Flush(true);   // push it through the OS cache to the disk
        }

        // 2. Keep the last good save, then swap the new one in
        if (File.Exists(path))
        {
            File.Copy(path, bak, true);
            File.Delete(path);
        }
        File.Move(tmp, path);
    }

    public static SaveData Load(string path)
    {
        foreach (string candidate in new[] { path, path + ".bak" })
        {
            if (!File.Exists(candidate))
                continue;

            string json = File.ReadAllText(candidate);
            if (JsonSafe.TryFromJson(json, out SaveData data))
                return data;

            // Move the bad file aside. It is evidence, and it must not overwrite the backup.
            string quarantine = candidate + ".corrupt.json";
            if (File.Exists(quarantine))
                File.Delete(quarantine);
            File.Move(candidate, quarantine);
            Debug.LogError($"Save rejected: {Path.GetFileName(candidate)}\n{json.Length} characters, kept as {Path.GetFileName(quarantine)}");
        }

        return new SaveData();   // first run, or nothing readable
    }
}

If the process dies during step 1, the real save is untouched. If it dies during step 2, the loader finds the backup. FileMode.Create also truncates, which removes the “root must not follow by other values” case: that one comes from opening an existing file with FileMode.OpenOrCreate and writing a shorter document over a longer one, or from File.AppendAllText. Tell the player when a backup or a fresh save was loaded. Silently starting them from zero reads as a wiped save. How to Reproduce and Diagnose a Save File Corruption Bug goes further into finding the write that went wrong.

For files that people edit by hand, such as mod or level data, the rules are stricter than most expect: double quotes only, no trailing commas, no comments. Catch the exception and show the file name and the parser’s message on screen so the author can fix it.

What JsonUtility does not read

Some “wrong” results are not parse errors at all. JsonUtility uses Unity’s serializer and follows the same rules as the Inspector, so several things are skipped without any message:

In your data or classWhat JsonUtility doesWhat to do
Top-level array, string or numberThrows JSON must represent an object type.Wrap it in a class (Fix 3)
Dictionary<K, V> fieldNot serialized. Missing from ToJson, untouched by FromJson.Use a list of key and value pairs
Properties ({ get; set; })Ignored. Only fields are read and written.Use public fields, or private fields with [SerializeField]
A nested class without [System.Serializable]The field is skippedAdd the attribute
A field typed as a base class holding a derived objectOnly the base class fields surviveStore a type id and separate data, or use another serializer
Nested lists, multidimensional arrays, nullable types such as int?Not serializedWrap the inner list in a serializable class
A MonoBehaviour or ScriptableObject as the target typeFromJson throws Cannot deserialize JSON to new instances of type 'X.'Use FromJsonOverwrite on an existing instance
A JSON key with no matching fieldIgnoredCheck the spelling and case of field names
A field with no matching JSON keyKeeps the value the constructor gave itSet defaults in field initializers

If your data depends on dictionaries, polymorphic types or arrays at the top level, or you are consuming a third-party API whose shape you do not control, a general-purpose JSON library is the better tool. Json.NET (Newtonsoft) is available as a Unity package. It reports bad input with its own exception types and messages, so the table at the top of this page does not apply to it. For small, flat save and config classes that you define yourself, JsonUtility is fast and has no dependencies.

How to confirm the fix

Damage the input on purpose and watch the game cope. Open the save file in a text editor and delete the second half. Replace it with a single space. Save it as UTF-8 with BOM. Add a trailing comma. Point the config URL at a page that returns HTML. Kill the process from the task manager while it is saving, several times. In each case the game should start, the Console or Player.log should show one of your own log lines naming the problem, and the damaged file should still exist under its .corrupt.json name.

Getting the bad JSON from a player’s machine

The Bugnet Unity SDK files what reaches Unity’s log as an error or exception, with the stack trace, recent log lines, game version, platform and OS. An uncaught JSON parse error is filed automatically, and because the variant is part of the message, Invalid value. and Missing a comma or '}' after an object member. become separate entries with their own occurrence counts. Once you catch the exception, as this guide recommends, nothing is filed unless you log it. The Debug.LogError in the loader above does that. Keep its first line free of player-specific text so that reports from different players stack into one entry.

Bugnet does not read the save file on its own, and the message alone will not tell you what the file contained. To see it, send the quarantined copy with a manual report: BugnetSDK.Instance.ReportBug("Save file rejected", details, attachmentPaths: new[] { quarantine }). The SDK accepts text and JSON attachments, up to 10 files of 10 MB each, which is why the quarantine name above ends in .json. A save or a server response can contain personal data, so attach deliberately. The bug reports guide shows where attachments appear.

Frequently asked questions

What does “ArgumentException: JSON parse error: Invalid value” mean in Unity?

JsonUtility found a character that cannot start a JSON value. The usual causes are an HTML error page returned by a server, a UTF-8 byte order mark in front of the opening brace, or plain text where JSON was expected. Log the first characters of the string to see which one you have.

Why does JsonUtility say “JSON must represent an object type”?

The JSON is valid, but its top level is an array, a string or a number, and JsonUtility only reads an object at the top level. Wrap the text in an object with one field and parse it into a small serializable class that has a matching array field.

Does JsonUtility.FromJson throw on an empty string?

No. It returns null for a null or empty string without raising anything, so the failure shows up later as a NullReferenceException. A string that contains only spaces or line breaks does throw, with the message JSON parse error: The document is empty.

How do I fix a JSON parse error caused by a byte order mark?

Remove the first character if it is U+FEFF before calling FromJson. File.ReadAllText strips the mark for you, while Encoding.UTF8.GetString keeps it. Saving the file as UTF-8 without BOM in your text editor fixes it at the source.

Why is my Unity save file corrupted after a crash?

Writing directly to the save file empties it first, so a crash or power cut during the write leaves half a file or a blank one. Write the new data to a temporary file, keep a backup of the previous save, and replace the real file only after the write has finished.

Log the length and the first characters of the string before you parse it. Nearly every JSON parse error is explained by what the text starts with or where it stops.