yamljsonmap

package module
v0.0.0-...-61ad123 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2016 License: MIT Imports: 3 Imported by: 0

README

yamljsonmap

A type to facilitate interoperability between yaml and json Marshaling and Unmarshaling.

When using go-yaml, unmarshalling yaml will result in map[interface{}]interface{} types. However, json.Marshal cannot marshal map[interface{}]interface{}.

This makes interoperability between the gopkg.in/yaml.v2 and encoding/json libraries problematic.

Solutions

One approach taken by github.com/ghodss/yaml is to convert Yaml to Json, and then Marshal from Json. However, with this approach you lose field ordering in a struct.

This approach adds a new type yamljsonmap.StringKeyMap which can be used in place of a map. It automatically converts map keys to strings when marshalling json and unmarshalling yaml.

Documentation

http://godoc.org/github.com/mtibben/yamljsonmap

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringKeyMap

type StringKeyMap map[string]interface{}

StringKeyMap is a map type that can be marshaled and unmarshalled from both yaml and json. It expects that map keys will always be a string type. json.Marshal cannot normally marshal map[interface{}]interface{} types, so this type allows interoperability between yaml and json

func (StringKeyMap) MarshalJSON

func (m StringKeyMap) MarshalJSON() ([]byte, error)

func (*StringKeyMap) UnmarshalYAML

func (m *StringKeyMap) UnmarshalYAML(unmarshal func(interface{}) error) error

Jump to

Keyboard shortcuts

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