Skip to content

Cannot unmarshal struct when key is not English #413

@artemklevtsov

Description

@artemklevtsov

Seems realted with #234.

package main

import (
	"fmt"

	"encoding/json"

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

type MyType struct {
	Msg string `json:"Сообщение"`
}

func main() {
	b := []byte(`{"Сообщение":"Текст"}`)

	var expected MyType
	json.Unmarshal(b, &expected)
	fmt.Printf("got json object: %+v\n", expected)

	var actual MyType
	gjson.Unmarshal(b, &actual)
	fmt.Printf("got gjson object: %+v\n", actual)
}

Exptected

got json object: {Msg:Текст}
got gjson object: {Msg:Текст}

Actual

got json object: {Msg:Текст}
got gjson object: {Msg:}
go version go1.19.3 linux/amd64
github.com/goccy/go-json v0.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions