Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: " ", SortKeys: false}
DefaultOptions is the default options for pretty formats.
Functions ¶
func PrettyOptions ¶
PrettyOptions is like Pretty but with customized options.
func Spec ¶
Spec 将注释和尾逗号替换为空白, 供普通 JSON 解析器处理扩展输入.
输入的注释和字符串语法完整时, 保留长度和换行位置, 便于外部解析器定位原始偏移. 本函数不校验 JSON 合法性, 也不修复其他语法错误或未闭合注释. JSON 规范: https://tools.ietf.org/html/rfc8259
func SpecInPlace ¶
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 ¶
Ugly removes insignificant space characters from the input json byte slice and returns the compacted result.
返回值总是新分配的独立副本, 即使输入本来就没有可删除的空白也不会与 json 共用底层数组.
func UglyInPlace ¶
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.
输入没有可删除的空白时直接返回 json 本身, 不写内存.
Types ¶
type Options ¶
type Options struct {
// Width 是单行数组或对象的最大列宽, 小于等于 0 时不尝试单行输出.
// 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
}
Options is Pretty options