Skip to content

encoding/json: int as map key error #65368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jk2K opened this issue Jan 30, 2024 · 1 comment
Closed

encoding/json: int as map key error #65368

jk2K opened this issue Jan 30, 2024 · 1 comment

Comments

@jk2K
Copy link

jk2K commented Jan 30, 2024

Go version

1.21

Output of go env in your module/workspace:

https://go.dev/play/p/sM0eZ_HtJuW
// You can edit this code!
// Click here and start typing.
package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	input := `{
    "aa": "bb",
    "636": {
        55538944: [
            {
                "bi": {},
                "clk": "99#null-null-null#55538944#dct&&&&",
                "deliveryId": 55538944,
                "itemid": "20373"
            }
        ]
    }
}`
	var data map[string]interface{}
	if err := json.Unmarshal([]byte(input), &data); err != nil {
		fmt.Printf("errors\n %v", err)
	}
	fmt.Println(data)
	fmt.Println("Hello, 世界")
}

What did you do?

https://go.dev/play/p/sM0eZ_HtJuW

What did you see happen?

invalid character '5' looking for beginning of object key stringmap[]

What did you expect to see?

no error

@mengzhuo
Copy link
Contributor

{55538944: []}

According to json spec, the key should be string instead of number https://www.json.org/

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
For questions please refer to https://github.com/golang/go/wiki/Questions

@mengzhuo mengzhuo closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@golang golang locked and limited conversation to collaborators Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants