nodeca / js-yaml

JavaScript YAML parser and dumper. Very fast.
http://nodeca.github.io/js-yaml/
MIT License
6.28k stars 769 forks source link

Quotes not preserved when reading YAML, then dumping it. #711

Closed aaronscribner closed 1 year ago

aaronscribner commented 1 year ago

If you read YAML and dump it, the content changes.

It fails to preserve the YAML and does not respect quoted values.

How I can have it keeps the quotes for the values in the YAML that are quoted, but leave the rest alone?

I have this

${application}: image: ${DOCKER_REGISTRY-}${application}:${IMAGE_TAG} build: context: . dockerfile: "${dockerfile}" args:

Looks like this when I force quotes, which is incorrect

Expected output

aaronscribner commented 1 year ago

FYI, I stopped using this library and switched to writing json files. This is too buggy and requires too many hacks.

rlidwka commented 1 year ago

If you read YAML and dump it, the content changes.

The content doesn't change. Only its representation does. Quotes in YAML are optional, so library may choose not to insert them.

js-yaml does not keep any information about original document (quotes, whitespace, comments) - these kind of things will get lost when dumping.

To keep that information, you'd need entirely different kind of library (not yaml loader, but yaml editor), and I'm not aware of any existing ones.

FYI, I stopped using this library and switched to writing json files.

Uhh... please look at yaml library. Or toml file format. Or json5. Or any other format that is suited for the job.

Writing config files in json is an extremely poor decision, since json is a data serialization format, not a config file format. It should never be written by humans (verbose syntax, lack of comments, etc.).