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

package yaml

import "github.com/oasdiff/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 UnmarshalWithOrigin

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

UnmarshalWithOrigin is like Unmarshal but if withOrigin is true, it will include the origin information in the output.

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.

type YAMLOpt

type YAMLOpt func(*yaml.Decoder) *yaml.Decoder

YAMLOpt is a decoding option for decoding from YAML format.

Source Files

fields.go yaml.go

Version
v0.0.0-20250309154309-f31be36b4037 (latest)
Published
Mar 9, 2025
Platform
windows/amd64
Imports
14 packages
Last checked
now

Tools for package owners.