Skip to content

Tools for roundtripping comments and aliases between YAML and JSON objects

License

Notifications You must be signed in to change notification settings

Mermade/yamltools

Repository files navigation

YAMLtools

ci

parseWithComments

This function takes a YAML string and an optional commentProperty, which defaults to $comment.

Comments in the YAML string are preserved in the JSON object using the commentProperty name.

stringifyWithComments

This function takes a JSON object and an optional commentProperty, which defaults to $comment.

Properties in the JSON object with the name of the commentProperty are stringified as YAML comments.

parseWithAliases

This function returns an object with a data property containing the parsed object, and an aliases property containing a Map of YAML aliases to their object representations.

Limitations

Because JSON objects cannot contain duplicate keys, comments may get concatenated when parsing.

Comments are not guaranteed to be attached to the same node when roundtripping.