github.com/fufuok/utils@v1.0.10/xjson/README.md (about) 1 ### 高效的 JSON 字符串操作库集 2 3 1. **只有 `1` 次内存分配的 JSON 字符串生成器** 4 5 见: [jsongen](xjson/jsongen) 6 7 或: [https://github.com/fufuok/jsongen](https://github.com/fufuok/jsongen) 8 9 ```go 10 package jsongen // import "github.com/fufuok/utils/xjson/jsongen" 11 12 Package jsongen forked from darjun/json-gen 13 14 type Array []Value 15 func NewArray() *Array 16 type Map struct{ ... } 17 func NewMap() *Map 18 type QuotedValue string 19 type RawBytes []byte 20 type RawString string 21 type UnquotedValue string 22 type Value interface{ ... } 23 func EscapeString(s string) Value 24 ``` 25 26 2. **超高效的 JSON 字符串解析和字段搜索** 27 28 来自: `tidwall/gjson` 29 30 见: [gjson](xjson/gjson) 31 32 ```go 33 package gjson // import "github.com/fufuok/utils/xjson/gjson" 34 35 Package gjson provides searching for json strings. 36 37 var DisableModifiers = false 38 func AddModifier(name string, fn func(json, arg string) string) 39 func AppendJSONString(dst []byte, s string) []byte 40 func ForEachLine(json string, iterator func(line Result) bool) 41 func ModifierExists(name string, fn func(json, arg string) string) bool 42 func Valid(json string) bool 43 func ValidBytes(json []byte) bool 44 type Result struct{ ... } 45 func Get(json, path string) Result 46 func GetBytes(json []byte, path string) Result 47 func GetMany(json string, path ...string) []Result 48 func GetManyBytes(json []byte, path ...string) []Result 49 func Parse(json string) Result 50 func ParseBytes(json []byte) Result 51 func (t Result) Array() []Result 52 func (t Result) Bool() bool 53 func (t Result) Exists() bool 54 func (t Result) Float() float64 55 func (t Result) ForEach(iterator func(key, value Result) bool) 56 func (t Result) Get(path string) Result 57 func (t Result) Int() int64 58 func (t Result) IsArray() bool 59 func (t Result) IsBool() bool 60 func (t Result) IsObject() bool 61 func (t Result) Less(token Result, caseSensitive bool) bool 62 func (t Result) Map() map[string]Result 63 func (t Result) Path(json string) string 64 func (t Result) Paths(json string) []string 65 func (t Result) String() string 66 func (t Result) Time() time.Time 67 func (t Result) Uint() uint64 68 func (t Result) Value() interface{} 69 type Type int 70 const Null Type = iota ... 71 ``` 72 73 3. **JSON 字符串字段修改和删除** 74 75 来自: `tidwall/sjson` 76 77 见: [sjson](xjson/sjson) 78 79 ```go 80 package sjson // import "github.com/fufuok/utils/xjson/sjson" 81 82 Package sjson provides setting json values. 83 84 func Delete(json, path string) (string, error) 85 func DeleteBytes(json []byte, path string) ([]byte, error) 86 func Set(json, path string, value interface{}) (string, error) 87 func SetBytes(json []byte, path string, value interface{}) ([]byte, error) 88 func SetBytesOptions(json []byte, path string, value interface{}, opts *Options) ([]byte, error) 89 func SetOptions(json, path string, value interface{}, opts *Options) (string, error) 90 func SetRaw(json, path, value string) (string, error) 91 func SetRawBytes(json []byte, path string, value []byte) ([]byte, error) 92 func SetRawBytesOptions(json []byte, path string, value []byte, opts *Options) ([]byte, error) 93 func SetRawOptions(json, path, value string, opts *Options) (string, error) 94 type Options struct{ ... } 95 ``` 96 97 4. **JSON 字符串格式化和校验** 98 99 来自: `tidwall/pretty` 100 101 见: [pretty](xjson/pretty) 102 103 ```go 104 package pretty // import "github.com/fufuok/utils/xjson/pretty" 105 106 var DefaultOptions = &Options{ ... } 107 func Color(src []byte, style *Style) []byte 108 func Pretty(json []byte) []byte 109 func PrettyOptions(json []byte, opts *Options) []byte 110 func Spec(src []byte) []byte 111 func SpecInPlace(src []byte) []byte 112 func Ugly(json []byte) []byte 113 func UglyInPlace(json []byte) []byte 114 type Options struct{ ... } 115 type Style struct{ ... } 116 var TerminalStyle *Style 117 ``` 118 119 5. 字符串模式匹配(`*?`通配符搜索) 120 121 来自: `tidwall/match` 122 123 见: [match](xjson/match) 124 125 ```go 126 package match // import "github.com/fufuok/utils/xjson/match" 127 128 Package match provides a simple pattern matcher with unicode support. 129 130 func Allowable(pattern string) (min, max string) 131 func IsPattern(str string) bool 132 func Match(str, pattern string) bool 133 func MatchLimit(str, pattern string, maxcomp int) (matched, stopped bool) 134 ``` 135 136 137 138 139 140 141 142 *ff*