Skip to content

bronze1man/go-yaml2json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codeship Status API Documentation MIT License

Convert YAML to JSON.

Installation

go get -u github.com/peter-edge/go-yaml2json

Import

import (
    "github.com/peter-edge/go-yaml2json"
)

Inspired by https://github.com/bronze1man/yaml2json, a command line tool with the same effect.

import (
	"encoding/json"
	"io/ioutil"
	"os"

	"github.com/peter-edge/go-yaml2json"
)

func ReadYamlToJson(yamlFilePath string) (interface{}, error) {
	yamlFile, err := os.Open(yamlFilePath)
	if err != nil {
		return nil, err
	}
	defer yamlFile.Close()
	yamlFileData, err := ioutil.ReadAll(yamlFile)
	if err != nil {
		return nil, err
	}
	jsonData, err := yaml2json.Convert(yamlFileData)
	if err != nil {
		return nil, err
	}
	var obj interface{}
	err = json.Unmarshal(jsonData, &obj)
	if err != nil {
		return nil, err
	}
	return obj, nil
}

Usage

func Convert

func Convert(input []byte) ([]byte, error)

About

Convert YAML to JSON for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published