Skip to content

encoding/json: json.RawMessage does not works correctly #35992

@gromas

Description

@gromas

I want to unmarshal JSON to different struct types and I write:

	bytes := []byte(`
		{"__type":"instance.started","InstanceId":"a9ff34dd-d20b-4887-99d6-f2f3a68f86a5"}
	`)
	var envelope struct {
		Type string `json:"__type"`
		Json *json.RawMessage
	}

        _ = json.Unmarshal(bytes, &envelope)

	fmt.Println(envelope.Type)
	fmt.Println(envelope.Json)

I get empty envelope.Json but must be an byte array (json.RawMessage).

repro:
https://play.golang.org/p/m6wd44R35FZ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions