yamlsigs.k8s.io/yaml/kyaml Index | Files

package kyaml

import "sigs.k8s.io/yaml/kyaml"

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:

KYAML is an output format, and will follow these conventions:

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

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

func (ky *Encoder) FromObject(obj any, out io.Writer) error

FromObject renders a KYAML document from a Go object, including the KYAML header. The result always has a trailing newline.

func (*Encoder) FromYAML

func (ky *Encoder) FromYAML(in io.Reader, out io.Writer) error

FromYAML renders a KYAML (multi-)document from YAML bytes (JSON is YAML), including the KYAML header. The result always has a trailing newline.

func (*Encoder) Marshal

func (ky *Encoder) Marshal(obj any) ([]byte, error)

Marshal renders a single Go object as KYAML, without the header or trailing newline.

Source Files

kyaml.go

Version
v1.6.0 (latest)
Published
Jul 24, 2025
Platform
js/wasm
Imports
12 packages
Last checked
9 months ago

Tools for package owners.