-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Question / Documentation: Is it possible to modify a value in an existing document without changing the rest of the document ? #574
Comments
@masenocturnal This is example code https://go.dev/play/p/QdwCh_tU-XR
|
Thank you so much for taking the time to educate me. This preserves the whole document including the comments and the spacing and the order! This is wonderful and it's great that you can do this with your library. In the example you provided the value of 'c' is not quoted as it is in the source. output
I tried creating a custom type and adding an custom marhsaler however it then appears to escape it ( i.e """) I suspect other people may also have this question / desire to modify part of a file. I'm happy to PR this either into the examples on the main page if that is appropriate place. |
I've done a bit of digging with the debugger and adding some quotes around the %s in the toString function in ast.go seems to result in the desired output.
to
Am I on the right track ? |
No, that is not where the fix should be made. If you need double-quote text, you can select two options.
1. Use double-quoted text directlyUse 2. Use ast.StringNode with DoubleQuote tokenSince ast.Node implements ast.String(token.DoubleQuote("foo", "foo", nil)) |
Is your feature request related to a problem? Please describe.
I have an existing YAML document below.
My goal is to modify the value of 'c' only, leaving the rest of the document as is.
I have tried the following and while the value is updated, the process of writing out the document modifies the order of the document , removes blank lines and other formatting which has been added.
Is it at all possible to preserve the original document and only change the values ? If so, would it be possible to offer some guidance as to the high level approach ?
I apologise if this has been answered elsewhere or should be obvious.
Thank you for your excellent library.
Describe alternatives you've considered
I've tried using the MarshalWithOptions and passing the the indent function but that only (as expected) addresses indentation.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: