yamljson

package
v3.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package json provides json specific functionality like rfc 6902 patching and convertion between json and yaml formatted maps.

Index

Constants

This section is empty.

Variables

View Source
var (
	JSONObjectPrefix = []byte("{")
	JSONArrayPrefix  = []byte("[")
)

Functions

func ConvertMapIToMapS

func ConvertMapIToMapS(mapI interface{}) interface{}

ConvertMapIToMapS will convert a map of the format created by yaml.Unmarshal to the format created by json.Unmarshal. Specifically, json uses string keys, while yaml uses interface{} keys.

https://stackoverflow.com/a/40737676/516433

func ConvertMapSToMapI

func ConvertMapSToMapI(mapS interface{}) interface{}

ConvertMapSToMapI will convert a map of the format created by json.Unmarshal to the format created by yaml.Unmarshal. Specifically, json uses string keys, while yaml uses interface{} keys.

https://stackoverflow.com/a/40737676/516433

func MarshalYaml

func MarshalYaml(in interface{}) ([]byte, error)

MarshalYaml will convert an object to yaml

func Patch

func Patch(data interface{}, patchBytes ...[]byte) (interface{}, error)

Patch applies a list of rfc 6902 patches to the data.

func PatchFromFiles

func PatchFromFiles(data interface{}, patchFiles ...string) (interface{}, error)

PatchFromFiles applies a list of rfc 6902 patches to the data.

func PatchFromStrings

func PatchFromStrings(data interface{}, patchStrings ...string) (interface{}, error)

PatchFromStrings applies a list of rfc 6902 patches to the data.

func UnmarshalAllYaml

func UnmarshalAllYaml(yamlString string) ([]interface{}, error)

UnmarshalAllYaml will unmarshal all yaml docs in a single yaml/json string without merging. This form works for any yaml data, not just objects.

func UnmarshalSingleYaml

func UnmarshalSingleYaml(yamlString string) (interface{}, error)

UnmarshalSingleYaml will unmarshal the first yaml doc in a single yaml/json string without merging. This form works for any yaml data, not just objects.

func UnmarshalYamlInterface

func UnmarshalYamlInterface(yamlStrings ...string) (interface{}, error)

UnmarshalYamlInterface will parse all the supplied yaml strings, merge the resulting objects, and return the resulting map. If a root node is a list it will be converted to an int map prior to merging. An emtpy document returns nil.

func YAMLToJSON

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

YAMLToJSON converts yaml bytes to json bytes. This is useful for other packages that have json specific unmarshaling code (ie: json-patch). The approach is inspired by:

https://github.com/kubernetes-sigs/yaml/blob/9535b3b1e2893fe44efb37c5c9f5665e245d786a/yaml.go

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL