Skip to content
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

Can we add an API for modifying JSON tag names of struct fields in Sonic library? #442

Closed
pokeyaro opened this issue May 29, 2023 · 2 comments

Comments

@pokeyaro
Copy link

I hope that Sonic library can add an API for modifying the JSON tag names of struct fields.

For example, I would like to modify the JSON tag name of the Name field in the User struct from "json:name" to "json:username". Since the tag information is determined at compile time, reflection mechanism is needed to dynamically modify the tag name.

func SetTag(s string) {
    //omit...
    field.Tag = reflect.StructTag(fmt.Sprintf(`json:"%s"`, s))
}
@liuq19
Copy link
Collaborator

liuq19 commented May 30, 2023

This is a simple demand that can be achieved using Golang reflection.

So it is not recommended to add this API in the Sonic JSON library.

@liuq19 liuq19 closed this as completed May 31, 2023
@liuq19 liuq19 reopened this May 31, 2023
@AsterDY
Copy link
Collaborator

AsterDY commented Jun 3, 2023

depulicated with #440

@AsterDY AsterDY closed this as completed Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants