Documentation
¶
Overview ¶
Package kyaml provides an encoder for KYAML, a strict subset of YAML that is designed to be explicit and unambiguous. KYAML is YAML, so any YAML parser should be able to read it.
KYAML is designed to be halfway between YAML and JSON, with the following properties:
- Not whitespace-sensitive
- Allows comments
- Allows trailing commas
- Does not require quoted keys
KYAML is an output format, and will follow these conventions:
- Always double-quote strings, even if they are not ambiguous.
- Only quote keys that might be ambiguously interpreted (e.g. "no" is always quoted).
- Always use `{}` for structs and maps, and `[]` for lists.
- Economize on vertical space by cuddling some kinds of brackets together.
- Render multi-line strings with YAML's line folding, which is close to the Go string literal format.
KYAML also includes a document-separator "header" (still valid YAML), which helps to disambiguate a KYAML document from an ill-formed JSON document.
Because KYAML is YAML, a KYAML multi-document is a YAML multi-document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct { // Compact tells the encoder to use compact formatting. This puts all the // data on one line, with no extra newlines, no comments, and no multi-line // formatting. Compact bool }
Encoder formats objects or YAML data (JSON is valid YAML) into KYAML. KYAML is halfway between YAML and JSON, but is a strict subset of YAML, so it should should be readable by any YAML parser. It is designed to be explicit and unambiguous, and eschews significant whitespace.
func (*Encoder) FromObject ¶
FromObject renders a KYAML document from a Go object, including the KYAML header. The result always has a trailing newline.