mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.48k stars 473 forks source link

Handle field names with non alphanumeric characters #99

Closed wvell closed 2 years ago

wvell commented 2 years ago

I am using gerrit code review which used this in the json of the rest api: {"-1":"Fails"}. This fails the gofmt as it results in a numeric field name.

This change checks if the sanitized field name is a number. If so it will preprend Num.

To avoid duplicate field names because of sanitizing values the code now keeps a map with used fields for the current struct.