Space at end of line will not result in yaml multiline string
gambrose opened this issue · comments
If we modify the example on the home page
echo '{"test":"test string with\nmultiple lines"}' | gojsontoyaml
test: |-
test string with
multiple lines
To include a space char after test string with
then the output is not a multiline yaml string as expected.
echo '{"test":"test string with \nmultiple lines"}' | gojsontoyaml
test: "test string with \nmultiple lines"
I think this is in line with the yaml spec, how would the multi-line string express the trailing whitespace?
I'm not too familiar with the intricacies of the yaml spec.
I was expecting
test: |-
test string with
multiple lines
I.e. the same as example but with a space at the end of line that says test string with
.
I think this is still valid yaml.
According to https://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines trailing spaces are kept when using |-
.
I found this issue when rendering out a k8s ConfigMap.
I had the contents of a config file render as a large ugly json string and it took me a while to workout why this was happening.
It's not that I want to keep the trailing whitespace it's more that having it results in difficult to diagnose issue as to why it was not using multiline output.