colorjson

package module
v0.0.0-...-a70d8b9 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 8 Imported by: 1

README

ColorJSON: The Fast Color JSON Marshaller for Go

ColorJSON Output What is this?

This package is based heavily on TylerBrock/colorjson but uses direct-to-stream serialisation to a io.Writer interface via an internal buffer.

Installation

go get -u github.com/relvacode/colorjson

Usage

Setup

import "github.com/relvacode/colorjson"

str := `{
  "str": "foo",
  "num": 100,
  "bool": false,
  "null": null,
  "array": ["foo", "bar", "baz"],
  "obj": { "a": 1, "b": 2 }
}`

// Create an intersting JSON object to marshal in a pretty format
var obj map[string]interface{}
json.Unmarshal([]byte(str), &obj)

Vanilla Usage

// Use stdout, or any other standard io.Writer interface
_, err := colorjson.Marshal(os.Stdout, obj)

Customization (Custom Indent)

f := colorjson.NewFormatter()
f.Indent = 2

_, err := f.Marshal(os.Stdout, obj)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(w io.Writer, jsonObj interface{}) (int, error)

Marshal JSON data with default options

Types

type Formatter

type Formatter struct {
	Buffer          *bufio.Writer
	KeyColor        *color.Color
	StringColor     *color.Color
	BoolColor       *color.Color
	NumberColor     *color.Color
	NullColor       *color.Color
	StringMaxLength int
	Indent          int
	DisabledColor   bool
	RawStrings      bool
}

func NewFormatter

func NewFormatter(w io.Writer) *Formatter

func (*Formatter) Marshal

func (f *Formatter) Marshal(jsonObj interface{}) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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