Help us shape the future of Go! Take the 2026 Go Developer Survey

jsonhl

package module
v0.0.0-...-75288bc Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

jsonhl

Go library to colorize JSON output of terminal applications.

Features

  • small and focused
  • colorizes JSON output without changing the JSON formatting

Usage

Using io.Reader and io.Writer:

jsonhl.Highlight(os.Stdin, os.Stdout)
jsonhl.HighlightC(os.Stdin, os.Stdout, jsonhl.DefaultColors)

Using strings:

fmt.Println(jsonhl.HighlightString(`{ "hello" : "world" }`))
fmt.Println(jsonhl.HighlightStringC(`{ "hello" : "world" }`, jsonhl.DefaultColors))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultColors = Colors{
	jsont.ObjectStart: "\x1b[38;5;242m",
	jsont.ObjectEnd:   "\x1b[38;5;242m",
	jsont.ArrayStart:  "\x1b[38;5;242m",
	jsont.ArrayEnd:    "\x1b[38;5;242m",
	jsont.Colon:       "\x1b[38;5;242m",
	jsont.Comma:       "\x1b[38;5;242m",
	jsont.FieldName:   "\x1b[38;5;33m",
	jsont.True:        "\x1b[38;5;22m",
	jsont.False:       "\x1b[38;5;124m",
	jsont.Null:        "\x1b[38;5;124m",
	jsont.Integer:     "\x1b[38;5;117m",
	jsont.Float:       "\x1b[38;5;117m",
	jsont.String:      "\x1b[38;5;45m",
	jsont.Unknown:     "\x1b[38;5;1m",
}

Functions

func Highlight

func Highlight(reader io.Reader, writer io.Writer) error

func HighlightBytes

func HighlightBytes(jsonString []byte, colors Colors) ([]byte, error)

func HighlightBytesC

func HighlightBytesC(jsonString []byte, colors Colors) ([]byte, error)

func HighlightC

func HighlightC(reader io.Reader, writer io.Writer, colors Colors) error

func HighlightString

func HighlightString(jsonString string) (string, error)

func HighlightStringC

func HighlightStringC(jsonString string, colors Colors) (string, error)

Types

type Colors

type Colors map[jsont.TokenType]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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