Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support YAML to pretty JSON #43

Open
davidxia opened this issue Sep 29, 2018 · 2 comments
Open

Support YAML to pretty JSON #43

davidxia opened this issue Sep 29, 2018 · 2 comments

Comments

@davidxia
Copy link
Contributor

davidxia commented Sep 29, 2018

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.

@davidxia
Copy link
Contributor Author

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

@daftspunk
Copy link

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants