# FormatException: Invalid UTF-8 byte sequence in JSON

- **ID:** `flutter/formatexception-invalid-json-utf8`
- **Domain:** flutter
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

A JSON response or file contains malformed UTF-8 bytes that Dart's utf8 decoder cannot parse, often due to corrupted data or encoding mismatch.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Dart 3.0 | active | — | — |
| Dart 3.2 | active | — | — |
| Flutter 3.16 | active | — | — |

## Workarounds

1. **Use a forgiving UTF-8 decoder that replaces invalid sequences, such as utf8.decode with allowMalformed: true, then parse the cleaned string as JSON.** (80% success)
   ```
   Use a forgiving UTF-8 decoder that replaces invalid sequences, such as utf8.decode with allowMalformed: true, then parse the cleaned string as JSON.
   ```
2. **Validate and sanitize the input at the network layer: log the raw bytes, then request the server to fix the encoding or use a fallback endpoint.** (70% success)
   ```
   Validate and sanitize the input at the network layer: log the raw bytes, then request the server to fix the encoding or use a fallback endpoint.
   ```

## Dead Ends

- **** — Silently drops data; the app continues with incomplete information, potentially causing downstream null errors or logic bugs. (70% fail)
- **** — utf8.encode expects valid strings; if the input is already corrupted, it will throw the same error or produce garbage. (85% fail)
- **** — Does not fix the underlying encoding issue; if the data is fundamentally corrupted, retrying will produce the same error. (65% fail)
