-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: encoding/json: export tagOptions, parseTag #60770
Comments
The fact that non-JSON packages are trying to use the JSON package's tags seems to suggest that there's a missing abstraction here, for defining the relationship between properties in a serialization format and Go struct fields in a format-agnostic way. While I expect it would be limited only to formats that have an infoset similar to JSON's, might it be better to expose a new struct tag scheme that is format-agnostic and then make To make this alternative a bit more concrete for discussion, consider: struct Example {
Foo string `marshal:"foo"`
} In the above, (I could also see just blessing "json" as the name for the general-purpose format as unfortunate but pragmatic, given that it paves an existing cowpath, but it is somewhat confusing for newcomers. I wonder what others think. I think accepting this proposal boils down to blessing "json" as the official format-agnostic name for "JSON-like" serialization formats -- whatever "JSON-like" might mean.) |
https://gist.github.com/sparr/008ebfab065bd00c3dd903fa43b9ad55 I actually drafted something along those lines but decided to submit this first as lower hanging fruit. |
To be clear, this proposal is about parsing what's inside a tag, the |
We already have |
If we're going to expose these, I might also recommend benchmarking I guess I should actually create that other proposal since that seems closer to what the feedback here is suggesting anyway. |
https://cs.opensource.google/go/go/+/master:src/encoding/json/tags.go
Multiple other packages reimplement similar functionality, including efforts to match the behavior of
encoding/json
:Exporting this functionality would allow those and similar packages to have convenient access to identical behavior to the json package. It would even allow them to safely parse the
json
tag, if they so choose.The text was updated successfully, but these errors were encountered: