# JsonSerializationException: Invalid JSON input for type 'PlayerData'

- **ID:** `unity/script-invalid-json-serialization`
- **Domain:** unity
- **Category:** data_error
- **Error Code:** `JSON-101`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The JSON string passed to JsonUtility.FromJson does not match the expected structure of the target class.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2021.3 | active | — | — |
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |

## Workarounds

1. **Validate the JSON string before deserialization using a JSON validator. Ensure fields match the class structure exactly (case-sensitive).** (90% success)
   ```
   Validate the JSON string before deserialization using a JSON validator. Ensure fields match the class structure exactly (case-sensitive).
   ```
2. **Use the [Serializable] attribute on the target class and ensure all fields are public or have [SerializeField].** (85% success)
   ```
   Use the [Serializable] attribute on the target class and ensure all fields are public or have [SerializeField].
   ```

## Dead Ends

- **Wrap the JSON parsing in a try-catch block and ignore the exception.** — Ignoring the exception leads to null data and potential runtime errors later. (70% fail)
- **Use Newtonsoft.Json instead of JsonUtility without changing the input format.** — If the JSON is malformed, Newtonsoft.Json will also fail or produce unexpected results. (50% fail)
