kbjson

package module
v0.0.0-...-9669a17 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

README

描述

  • 自用学习库,仅支持自己学习

Documentation

Overview

kbjson2Json data read and write operations

Index

Constants

View Source
const (
	PadRight int = iota //向右填充字符
	PadLeft             //向左填充字符
)

Variables

View Source
var (
	DefOptions = &StFormatOptions{Width: 80, Prefix: "", Indent: "  ", SortKeys: false}
	Matches    = []Map{
		{"start": "//", "end": "\n"},
		{"start": "/*", "end": "*/"},
	}
)
View Source
var (
	ErrNoChange              = errors.New("no change")
	ErrPathEmpty             = errors.New("path cannot be empty")
	ErrInvalidJSON           = errors.New("invalid json")
	ErrNotAllowedWildcard    = errors.New("wildcard characters not allowed in path")
	ErrNotAllowedArrayAccess = errors.New("array access character not allowed in path")
	ErrTypeError             = errors.New("json must be an object or array")
)

Functions

func AddModifier

func AddModifier(name string, fn func(json, arg string) string)

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String bytes to string

func Delete

func Delete(json, path string) (string, error)

func DeleteBytes

func DeleteBytes(json []byte, path string) ([]byte, error)

func Discard

func Discard(json string) (string, error)

func ForEachLine

func ForEachLine(json string, iterator func(line JsonRes) bool)

func Format

func Format(json []byte) []byte

func FormatOptions

func FormatOptions(json []byte, opts *StFormatOptions) []byte

func Len

func Len(str string) int

Len string length (utf8)

func Marshal

func Marshal(json interface{}) ([]byte, error)

func Match

func Match(str, pattern string) bool

-------- 字符串匹配 字符串匹配

func ModifierExists

func ModifierExists(name string) bool

func ModifiersState

func ModifiersState() bool

func Pad

func Pad(raw string, length int, padStr string, padType int) string

Pad String padding

func Set

func Set(json, path string, value interface{}) (string, error)

func SetBytes

func SetBytes(json []byte, path string, value interface{}) ([]byte, error)

func SetBytesOptions

func SetBytesOptions(json []byte, path string, value interface{},
	opts *Options) ([]byte, error)

func SetModifiersState

func SetModifiersState(b bool)

func SetOptions

func SetOptions(json, path string, value interface{},
	opts *Options) (string, error)

func SetRaw

func SetRaw(json, path, value string) (string, error)

func SetRawBytes

func SetRawBytes(json []byte, path string, value []byte) ([]byte, error)

func SetRawBytesOptions

func SetRawBytesOptions(json []byte, path string, value []byte,
	opts *Options) ([]byte, error)

func SetRawOptions

func SetRawOptions(json, path, value string, opts *Options) (string, error)

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes string to bytes

func Stringify

func Stringify(value interface{}) (json string)

func TrimSpace

func TrimSpace(s string) string

TrimSpace TrimSpace

func Ugly

func Ugly(json []byte) []byte

func Unmarshal

func Unmarshal(json, v interface{}) error

func UnmarshalValidationEnabled

func UnmarshalValidationEnabled(enabled bool)

func Valid

func Valid(json string) (ok bool)

func ValidBytes

func ValidBytes(json []byte) bool

Types

type JsonRes

type JsonRes struct {
	Type  Type
	Raw   string
	Str   string
	Num   float64
	Index int
}

func Get

func Get(json, path string) JsonRes

func GetBytes

func GetBytes(json []byte, path string) JsonRes

func GetMultiple

func GetMultiple(json string, path ...string) []JsonRes

func GetMultipleBytes

func GetMultipleBytes(json []byte, path ...string) []JsonRes

func Parse

func Parse(json string) JsonRes

func ParseBytes

func ParseBytes(json []byte) JsonRes

func (JsonRes) Array

func (r JsonRes) Array() []JsonRes

func (JsonRes) Bool

func (r JsonRes) Bool() bool

func (JsonRes) Exists

func (r JsonRes) Exists() bool

func (JsonRes) Float

func (r JsonRes) Float() float64

func (JsonRes) ForEach

func (r JsonRes) ForEach(iterator func(key, value JsonRes) bool)

func (JsonRes) Get

func (r JsonRes) Get(path string) JsonRes

func (JsonRes) Int

func (r JsonRes) Int() int

func (JsonRes) IsArray

func (r JsonRes) IsArray() bool

func (JsonRes) IsObject

func (r JsonRes) IsObject() bool

func (JsonRes) Map

func (r JsonRes) Map() map[string]JsonRes

func (JsonRes) String

func (r JsonRes) String() string

func (JsonRes) Time

func (r JsonRes) Time(format ...string) time.Time

func (JsonRes) Uint

func (r JsonRes) Uint() uint

func (JsonRes) Unmarshal

func (r JsonRes) Unmarshal(v interface{}) error

func (JsonRes) Value

func (r JsonRes) Value() interface{}

type Map

type Map map[string]string

type Options

type Options struct {
	Optimistic     bool
	ReplaceInPlace bool
}

type StFormatOptions

type StFormatOptions struct {
	Width    int
	Prefix   string
	Indent   string
	SortKeys bool
}

type Type

type Type int
const (
	Null Type = iota
	False
	Number
	String
	True
	JSON
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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