transcode

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 6 Imported by: 1

README

transcode is markup language conversion library

Go Reference

transcode is a go library that will convert markup languages (currently JSON and YAML) from one form to another.

Motivation

While it is possible to decode JSON as YAML, doing so comes with caveats. YAML is a superset of JSON and so unmarshaling a YAML object into interface{} will result in map[interface{}]interface{}. When you need to work with the raw data or would like to work with JSON Schema, this can be problematic.

Encoding JSON as YAML is easily accomplishable with standard tooling. However, this library will be faster than unmarshaling JSON as interface{}, and then remarshaling as YAML. It also provides some very minimal formatting.

There are some drawbacks to using transcode though:

  • YAML aliases are not supported
  • All keys remain strings when transcoding into YAML
  • YAML comments are obviously lost

License

MIT

Documentation

Overview

Package transcode is a library that will convert markup languages (currently JSON and YAML) from one form to another.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONFromYAML

func JSONFromYAML(yamlData []byte) ([]byte, error)

func YAMLFromJSON

func YAMLFromJSON(jsonData []byte) ([]byte, error)

Types

type Transcoder

type Transcoder struct {
	Indent int
	// contains filtered or unexported fields
}

func New

func New(w io.Writer) Transcoder

func (Transcoder) JSONFromYAML

func (t Transcoder) JSONFromYAML(yamlData io.Reader) error

JSONFromYAML transcodes YAML contained in yamlData

Multiple documents are not supported.

func (Transcoder) YAMLFromJSON

func (t Transcoder) YAMLFromJSON(jsonData io.Reader) error

YAMLFromJSON transcodes JSON contained in jsonData into YAML

Transcoding multiple items are not supported. Each root record will be seperated by "---"

Jump to

Keyboard shortcuts

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