yaml – github.com/invopop/yaml Index | Files

package yaml

import "github.com/invopop/yaml"

Package yaml provides a wrapper around go-yaml designed to enable a better way of handling YAML when marshaling to and from structs.

In short, this package first converts YAML to JSON using go-yaml and then uses json.Marshal and json.Unmarshal to convert to or from the struct. This means that it effectively reuses the JSON struct tags as well as the custom JSON methods MarshalJSON and UnmarshalJSON unlike go-yaml.

Index

Functions

func JSONToYAML

func JSONToYAML(j []byte) ([]byte, error)

JSONToYAML converts JSON to YAML.

func Marshal

func Marshal(o interface{}) ([]byte, error)

Marshal the object into JSON then converts JSON to YAML and returns the YAML.

func Unmarshal

func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error

Unmarshal converts YAML to JSON then uses JSON to unmarshal into an object, optionally configuring the behavior of the JSON unmarshal.

func YAMLToJSON

func YAMLToJSON(y []byte) ([]byte, error)

YAMLToJSON converts YAML to JSON. Since JSON is a subset of YAML, passing JSON through this method should be a no-op.

Things YAML can do that are not supported by JSON:

Types

type JSONOpt

type JSONOpt func(*json.Decoder) *json.Decoder

JSONOpt is a decoding option for decoding from JSON format.

Source Files

fields.go yaml.go

Version
v0.3.1 (latest)
Published
Apr 8, 2024
Platform
js/wasm
Imports
14 packages
Last checked
now

Tools for package owners.