profile
viewpoint

Ask questionsTrailing spaces force quoted string encoding

I use yaml.Unmarshal to Unmarshal a file. image

image

The file is as follows: image

Then I change the struct

image

Then I use Marshal to reverse it: image

The output is as follows: image the output is Completely messed up,Who can tell me How can I preserve the original format? I expect the output looks like that: image Many thanks!

go-yaml/yaml

Answer questions niemeyer

The yaml package will already format it as suggested automatically, as long as the string contains newlines. The fact this heuristic is not working for your case probably implies that the content being marshaled contains unusual characters that had to be quoted to be parsed properly. Can you please provide a reproducer using https://play.golang.org so we can look into it?

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