When marshalling if the variable reference is nil then json lib encodes it as nil. But for an empty slice preferred would be to have [].

package main

import (

func main() {
	var ids []int
	m := make(map[string]interface{})
	m["ids"] = ids
	b, err := json.Marshal(m)
	if err != nil {
	fmt.Printf("%s", string(b))

this would print {"ids":null}, the trick is to initialize ids with

ids := []int{}
  • or -
ids := make([]int, 0)