# json: unexpected end of JSON input

- **ID:** `go/json-unexpected-end-of-json-input`
- **Domain:** go
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The JSON decoder encountered the end of the input stream before completing the parsing of a valid JSON value.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## Workarounds

1. **Check the source of the JSON data to ensure it is complete (e.g., full HTTP response body, complete file read). Use io.ReadAll to read all data before unmarshaling.** (90% success)
   ```
   Check the source of the JSON data to ensure it is complete (e.g., full HTTP response body, complete file read). Use io.ReadAll to read all data before unmarshaling.
   ```
2. **Use json.Decoder with a buffered reader and check for io.ErrUnexpectedEOF specifically to provide a better error message.** (85% success)
   ```
   Use json.Decoder with a buffered reader and check for io.ErrUnexpectedEOF specifically to provide a better error message.
   ```

## Dead Ends

- **Adding more fields to the Go struct to match the expected JSON.** — The error is about incomplete input, not missing fields; adding fields doesn't fix malformed or truncated data. (80% fail)
- **Using json.Unmarshal with a string that includes extra whitespace.** — Whitespace is ignored by the decoder; the input must be a complete JSON value. (70% fail)
