Skip to content

Bug: struct with map (the only one field) encoded to null #376

@trim21

Description

@trim21
package main

import (
	"fmt"
	"testing"

	"github.com/goccy/go-json"
)

func main() {
	type Container struct {
		V any `json:"value"`
	}
	type MapOnly struct {
		Map map[string]int64 `json:"map"`
	}

	b, err := json.Marshal(Container{MapOnly{}})
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))
}

output: {"value":null}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions