Getting current viewers, JSON issues in Golang

Hey all,

Trying to get a list of all viewers using

I am using a Golang struct to unmarshal the JSON into.

type Viewers struct {
ChatterCount string `json:"chatter_count"`
Chatters     []struct {
	Viewers []string `json:"viewers"`
} `json:"chatters"`


This setup returns empty slices/arrays.

I have another struct for other API data as seen below, which works fine.

type Stream struct {
	Data []struct {
		ID           string    `json:"id"`
		UserID       string    `json:"user_id"`
		GameID       string    `json:"game_id"`
		CommunityIds []string  `json:"community_ids"`
		Type         string    `json:"type"`
		Title        string    `json:"title"`
		ViewerCount  int       `json:"viewer_count"`
		StartedAt    time.Time `json:"started_at"`
	} `json:"data"`

Any insight into what I’m missing would be awesome!

UPDATE: Changing the chattercount from string to int is now getting me expected results, but actual list of viewers is still empty.

Okay, I’ve actually fixed it, below is the final struct

type Viewers struct {
	ChatterCount int `json:"chatter_count"`
	Chatters     struct {
		CurrentModerators []string `json:"moderators"`
		CurrentViewers    []string `json:"viewers"`
	} `json:"chatters"`

It wasn’t working when I set Chatters to be an array of objects, unlike the Stream struct I had above.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.