# error: json: error calling MarshalJSON for type time.Duration

- **ID:** `go/encoding-json-marshal-time-duration`
- **Domain:** go
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

time.Duration does not implement json.Marshaler and is marshaled as a nanosecond integer, which may not be intended.

## Version Compatibility

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

## Workarounds

1. **Create a custom type that marshals duration as string** (90% success)
   ```
   type Duration time.Duration
func (d Duration) MarshalJSON() ([]byte, error) {
    return json.Marshal(time.Duration(d).String())
}
   ```

## Dead Ends

- **Using string formatting to convert duration** — Inconsistent output; use custom type with MarshalJSON. (60% fail)
