panic: interface conversion Go Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Go

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

  1. v, ok := x.(int); if !ok { … }
  2. Use a type switch for several types
  3. Decode JSON into typed structs instead of interface{}

Detailed fix by platform

Go

  1. switch t := x.(type) { case int: … case float64: … case string: … default: … }

How to diagnose

  1. Dynamic type — Actual vs expected?
  2. Form — ok-check used?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

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) (Go)does not implement in…fatal error: stack overflow — Go: runtime: goroutine stack exceeds 1000000000-byte limit — fatal error: stack overflow (Go)fatal error: stack ov…invalid memory address or nil pointer dereference — Go: panic: runtime error: invalid memory address or nil pointer dereference (Go)invalid memory addres…json: cannot unmarshal string into Go struct field — Go: json: cannot unmarshal string into Go struct field User.age of type int (Go)json: cannot unmarsha…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …panic: runtime error: index out of range — Go: panic: runtime error: index out of range [3] with length 3 (Go)panic: runtime error:…panic: runtime error: integer divide by zero — Go: panic: runtime error: integer divide by zero (Go)panic: runtime error:…panic: slice bounds out of range — Go: panic: runtime error: slice bounds out of range [:5] with capacity 3 (Go)panic: slice bounds o…panic: in…

Explore the map of this error Full error map →

🧠 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.