Golang – Cannot unmarshal number into Go value of type string


When trying to json.Unmarshal some JSON code from a website into a struct I created, I receive the following error:

cannot unmarshal number into Go value of type string

Here is my code: https://play.golang.org/p/-5nphV9vPw


this works for me (corrected version):

package main

import (

type movie struct {
    Adult         bool
    Backdrop_path string
    Budget        int
    Genres        []struct {
        Id   int // string
        Name string
    Homepage             string
    Id                   int
    Imdb_id              string
    Original_language    string
    Original_title       string
    Overview             string
    Popularity           float64 //    string
    Poster_path          string
    Production_companies []struct {
        Name string
        Id   int
    Production_countries []struct {
        Name string
    Release_date     string
    Revenue          int
    Runtime          int
    Spoken_languages []struct {
        Name string
    Status       string
    Tagline      string
    Title        string
    Video        bool
    Vote_average float64
    Vote_count   int
    Embedurl     string

func main() {
    var movieData movie
    str := `
    "original_title":"¡Three Amigos!",
    "overview":"Three unemployed actors accept an invitation to a Mexican village to replay their bandit fighter roles, unaware that it is the real thing.",
        "name":"L.A. Films",
        "name":"Home Box Office (HBO)",
        "name":"United States of America"
    "tagline":"They're Down On Their Luck And Up To Their Necks In Senoritas, Margaritas, Banditos And Bullets!",
    "title":"Three Amigos",
    err := json.Unmarshal([]byte(str), &movieData)
    if err != nil {

Answered By – user6169399

Answer Checked By – Terry (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.