jc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: Apache-2.0 Imports: 5 Imported by: 7

README

jc

convert between JSON-like formats

jc

Install

go install -u github.com/taskie/jc/cmd/jc

Usage

Convert
jc foo.json foo.yaml
jc foo.yaml foo.toml
jc foo.toml foo.msgpack
jc foo.msgpack foo.json

or

jc -t yaml <foo.json >foo.yaml
jc -f yaml -t toml <foo.yaml >foo.toml
jc -f toml -t msgpack <foo.toml >foo.msgpack
jc -f msgpack <foo.msgpack >foo.json
Input File (foo.json)
{"message":[{"hello":true},{"world":42}]}
Output File (foo.yaml)
message:
- hello: true
- world: 42
Output File (foo.toml)
[[message]]
  hello = true

[[message]]
  world = 42
Output File (foo.msgpack)
xxd foo.msgpack
00000000: 81a7 6d65 7373 6167 6592 81a5 6865 6c6c  ..message...hell
00000010: 6fc3 81a5 776f 726c 64d3 0000 0000 0000  o...world.......
00000020: 002a                                     .*

Dependency

dependency

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = "0.1.0"
)

Functions

func DecodeFile

func DecodeFile(fpath string, ty string, data interface{}) error

func EncodeFile

func EncodeFile(fpath string, ty string, data interface{}) error

func ExtToType

func ExtToType(ext string) string

Types

type Converter

type Converter struct {
	Resolver *codecs.CodecResolver
	FromType string
	ToType   string
	Indent   *string
}

func (*Converter) Convert

func (c *Converter) Convert(dst io.Writer, src io.Reader) error

func (*Converter) Decode

func (c *Converter) Decode(r io.Reader, data interface{}) error

func (*Converter) Encode

func (c *Converter) Encode(w io.Writer, data interface{}) error

type Decoder

type Decoder struct {
	Resolver *codecs.CodecResolver
	Reader   io.Reader
	Type     string
}

func NewDecoder

func NewDecoder(r io.Reader, ty string) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(data interface{}) error

type Encoder

type Encoder struct {
	Resolver *codecs.CodecResolver
	Writer   io.Writer
	Type     string
	Indent   *string
}

func NewEncoder

func NewEncoder(w io.Writer, ty string) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(data interface{}) error

Directories

Path Synopsis
cli
jc
cmd
jc

Jump to

Keyboard shortcuts

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