Documentation ¶
Index ¶
- func JSONtoYAMLBytes(jsonBytes []byte) ([]byte, error)
- func JSONtoYAMLMapSlice(jsonBytes []byte) (interface{}, error)
- func Marshal(in interface{}) (out []byte, err error)
- func UnmarshalerToJSONBytes(unmarshal func(interface{}) error) ([]byte, error)
- func YAMLtoJSONBytes(yamlBytes []byte) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONtoYAMLBytes ¶
JSONtoYAMLBytes converts json data to yaml output while preserving order of object fields.
func JSONtoYAMLMapSlice ¶
JSONtoYAMLMapSlice decodes JSON bytes into an interface{} where all objects and maps are decoded as a yaml.MapSlice to preserve key ordering. This can be useful if a type defines custom JSON marshal logic and translating the JSON representation to a YAML representation while preserving key ordering is sufficient for serialization. For example:
func (o Foo) MarshalYAML() (interface{}, error) { jsonBytes, err := json.Marshal(o) if err != nil { return nil, err } return JSONtoYAML(jsonBytes) }
func UnmarshalerToJSONBytes ¶
UnmarshalerToJSONBytes decodes YAML bytes using the provided unmarshal function, converts the object to a JSON-compatible representation and returns the result of marshalling the converted object as JSON. This can be used in an UnmarshalYAML implementation where the type implements custom UnmarshalJSON behavior and wants it to apply to YAML as well. For example:
func (o *Foo) UnmarshalYAML(unmarshal func(interface{}) error) error { jsonBytes, err := safeyaml.YAMLUnmarshalerToJSONBytes(unmarshal) if err != nil { return err } return json.Unmarshal(jsonBytes, o) }
func YAMLtoJSONBytes ¶
YAMLtoJSONBytes converts YAML content to JSON. Returns an error if it encounters types that are invalid in JSON but valid in YAML (e.g. non-string map keys).
Types ¶
This section is empty.