json2yaml

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 6 Imported by: 10

README

json2yaml

CI Status Go Report Card MIT License release pkg.go.dev

This is an implementation of JSON to YAML converter written in Go language. This tool efficiently converts each JSON tokens in streaming fashion, so it avoids loading the entire JSON on the memory. Also, this tool preserves the order of mapping keys and the number representation.

Usage as a command line tool

json2yaml file.json ...
json2yaml <file.json >output.yaml

You can combine with other command line tools.

gh api /meta | json2yaml | less

Usage as a library

You can use the converter as a Go library. json2yaml.Convert(io.Writer, io.Reader) error is exported.

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/itchyny/json2yaml"
)

func main() {
	input := strings.NewReader(`{"Hello": "world!"}`)
	var output strings.Builder
	if err := json2yaml.Convert(&output, input); err != nil {
		log.Fatalln(err)
	}
	fmt.Print(output.String()) // outputs Hello: world!
}

Installation

Homebrew
brew install itchyny/tap/json2yaml
Build from source
go install github.com/itchyny/json2yaml/cmd/json2yaml@latest

Bug Tracker

Report bug at Issues・itchyny/json2yaml - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

Documentation

Overview

Package json2yaml implements a converter from JSON to YAML.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(w io.Writer, r io.Reader) error

Convert reads JSON from r and writes YAML to w.

Example
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/itchyny/json2yaml"
)

func main() {
	input := strings.NewReader(`{"Hello": "world!"}`)
	var output strings.Builder
	if err := json2yaml.Convert(&output, input); err != nil {
		log.Fatalln(err)
	}
	fmt.Print(output.String())
}
Output:

Hello: world!

Types

This section is empty.

Directories

Path Synopsis
cmd
json2yaml
json2yaml - convert JSON to YAML
json2yaml - convert JSON to YAML

Jump to

Keyboard shortcuts

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