Go: panic: interface conversion: interface {} is string, not int
A type assertion x.(T) failed because the dynamic type of the interface is not T.
panic: interface conversion: interface {} is string, not intinterface conversion: interface is nil, notinterface conversion: interface {} is float64, not intinterface conversion: *main.Dog is not main.Cat: missing methodpanic: interface conversion Meaning
Use the two-value form v, ok := x.(T) to check safely, or a type switch. interface conversion: interface is nil, not X means the interface holds nil. JSON decoding into interface{} yields float64 for numbers, not int.
Common causes
- Asserting without the ok form
- JSON numbers decoded as float64
- Nil interface value
- Wrong type stored in map[string]interface{}
- Pointer vs value type mismatch
⚡ Quick fix
v, ok := x.(int); if !ok { … }- Use a type switch for several types
- Decode JSON into typed structs instead of interface{}
Detailed fix by platform
Go
switch t := x.(type) { case int: … case float64: … case string: … default: … }
How to diagnose
- Dynamic type — Actual vs expected?
- Form — ok-check used?
- JSON — float64?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- does not implement interface (missing method) Go: cannot use &Dog{} (value of type *Dog) as Animal value: *Dog does not implement Animal (missing method Speak)
- fatal error: stack overflow Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow
- invalid memory address or nil pointer dereference Go: panic: runtime error: invalid memory address or nil pointer dereference
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026