profile
viewpoint

Ask questionsPlease allow the struct tag to be changed to "json"

I find no way to tell the yaml package to just use "json" as the tag. This is quite unfortunate because I have no control over the generated structs (which are actually produced by the protobuf compiler and get json tags by default) but I need to parse these from YAML.

I would be rather trivial to provide an option as the name of the tag to use. TBH the state of go right now is that most people add json tags to their structs but not yaml tags. It is quite pointless to add multiple tags and often we have no control over the structs (because they came from someone else's code).

This has been hacked around in the past using e.g. github.com/ghodss/yaml but it is fragile and hacky. The easier solution for us right now is to just fork this repo and do a 3 char change :-).

go-yaml/yaml

Answer questions niemeyer

We will certainly have something along the lines of MarshalWithOptions.. this is already in progress in a different issue and PR, and I'm behind on getting it in.

That's unrelated to supporting compatibility across the two marshalers, though. Their behavior is not the same today, and it's not just a matter of reading it from a different tag and it'll all be alright. If you want to dig in, feel free to try to run the json test suite with the yaml marshaler, while simply hacking the tag, and let us know of your experience.

useful!

Related questions

v3 panics on bad input hot 1
v3 equivalent of v2's MapSlice and MapItem? hot 1
unmarshal with comments provide wrong structure hot 1
Head comments in list elements misplaced hot 1
source:https://uonfu.com/
Github User Rank List