# json: error calling MarshalJSON for type MyStruct: custom error

- **ID:** `go/encoding-json-marshaler-error`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A custom MarshalJSON method returns an error, causing json.Marshal to fail.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.20 | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   func (m MyStruct) MarshalJSON() ([]byte, error) { if m.Invalid { return nil, errors.New("invalid state") }; return json.Marshal(m.Alias) }
   ```

## Dead Ends

- **** — Loses custom serialization logic, may produce wrong output. (70% fail)
- **** — Panic propagates and crashes the program. (90% fail)
