import "github.com/fufuok/utils/xjson/pretty"
- Variables
- func Color(src []byte, style *Style) []byte
- func Pretty(json []byte) []byte
- func PrettyOptions(json []byte, opts *Options) []byte
- func Spec(src []byte) []byte
- func SpecInPlace(src []byte) []byte
- func Ugly(json []byte) []byte
- func UglyInPlace(json []byte) []byte
- type Options
- type Style
DefaultOptions is the default options for pretty formats.
var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: " ", SortKeys: false}
func Color(src []byte, style *Style) []byte
Color will colorize the json. The style parma is used for customizing the colors. Passing nil to the style param will use the default TerminalStyle.
func Pretty(json []byte) []byte
Pretty converts the input json into a more human readable format where each element is on it's own line with clear indentation.
func PrettyOptions(json []byte, opts *Options) []byte
PrettyOptions is like Pretty but with customized options.
func Spec(src []byte) []byte
Spec strips out comments and trailing commas and convert the input to a valid JSON per the official spec: https://tools.ietf.org/html/rfc8259
The resulting JSON will always be the same length as the input and it will include all of the same line breaks at matching offsets. This is to ensure the result can be later processed by a external parser and that that parser will report messages or errors with the correct offsets.
func SpecInPlace(src []byte) []byte
SpecInPlace is the same as Spec, but this method reuses the input json buffer to avoid allocations. Do not use the original bytes slice upon return.
func Ugly(json []byte) []byte
Ugly removes insignificant space characters from the input json byte slice and returns the compacted result.
func UglyInPlace(json []byte) []byte
UglyInPlace removes insignificant space characters from the input json byte slice and returns the compacted result. This method reuses the input json buffer to avoid allocations. Do not use the original bytes slice upon return.
Options is Pretty options
type Options struct {
// Width is an max column width for single line arrays
// Default is 80
Width int
// Prefix is a prefix for all lines
// Default is an empty string
Prefix string
// Indent is the nested indentation
// Default is two spaces
Indent string
// SortKeys will sort the keys alphabetically
// Default is false
SortKeys bool
}
Style is the color style
type Style struct {
Key, String, Number [2]string
True, False, Null [2]string
Escape [2]string
Append func(dst []byte, c byte) []byte
}
TerminalStyle is for terminals
var TerminalStyle *Style
Generated by gomarkdoc