ghodss/yaml

Support YAML to pretty JSON

davidxia opened this issue · 2 comments

Thanks for this library!

Right now YAMLToJSON prints the following YAML

t: a

as {"t":"a"}.

Could you add support for printing the YAML as

{
  "t": "a"
}

Basically add a way to use json.MarshalIndent here.

I tried making a PR, but I'm not that good at go :(

This might help

// Compile JSON
body, err := yaml.YAMLToJSON(yamlContents)
if err != nil {
	panic(err)
}

// Beautify
var schemaObj map[string]interface{}

if err := json.Unmarshal(body, &schemaObj); err != nil {
	panic(err)
}

body, err := json.MarshalIndent(schemaObj, "", "  ")
if err != nil {
	panic(err)
}