Skip to content

Handle field names with non alphanumeric characters #99

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

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

wvell
Copy link
Contributor

@wvell wvell commented Sep 17, 2021

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.

When supplying a payload of {"-1":"Fails"} the fieldname will be 1.
This will fail when running gofmt(and is not a valid go identifier).
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.
Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix -- let's give it a try.

@mholt mholt merged commit a3f1f63 into mholt:master Sep 17, 2021
pincher95 added a commit to pincher95/json-to-go that referenced this pull request Oct 20, 2021
Handle field names with non alphanumeric characters (mholt#99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants