-
Notifications
You must be signed in to change notification settings - Fork 42
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
Preserve comments on source file #51
Comments
I don't know of any solution for structs, because the tags on structs are declared in the struct declaration and cannot be altered after that. One solution I could do is to create a special |
Yeah I think that could work. To be clear my goal is not to read & write comments even though it would be a nice feature to have. My goal is to preserve comments, and change the key-value data. Then save my changed data back to json while keeping the comments unchanged. |
In the new release v4.3.0 you can read-change-write with preserved comments and whitespace for example like this: var node hjson.Node
if err := hjson.Unmarshal(txt, &node); err != nil {
panic(err)
}
if _, _, err := node.SetKey("myKey", "myValue"); err != nil {
panic(err)
}
outBytes, err := hjson.Marshal(node)
if err != nil {
panic(err)
} |
I was wondering if there is a way to Unmarshal
hjson
to a go struct but preserve arbitrary comments on the source json. For example if my hjson looks like this:I want to preserve a comment on a random line in the json, unmarshal the file to a go struct, change
bar
tobar-modified
.Then marshal and save to file.
Is it possible to preserve comments when you don't know which line might have a comment on it?
The text was updated successfully, but these errors were encountered: