colorjson

package module
v0.0.0-...-9def3a5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 9 Imported by: 0

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

Marshal JSON data with default options

Types

type Formatter

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

func NewFormatter

func NewFormatter(w io.Writer) *Formatter

func (*Formatter) Encode

func (f *Formatter) Encode(jsonObj interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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