json

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0, MIT Imports: 27 Imported by: 2

Documentation

Index

Constants

View Source
const (
	JSON_KEY_NULL        = '\x00'
	JSON_KEY_NUMBER_NEG  = '\x01'
	JSON_KEY_NUMBER_ZERO = '\x02'
	JSON_KEY_NUMBER_POS  = '\x03'
	JSON_KEY_STRING      = '\x04'
	JSON_KEY_OBJECT      = '\x05'
	JSON_KEY_ARRAY       = '\x06'
	JSON_KEY_FALSE       = '\x07'
	JSON_KEY_TRUE        = '\x08'
	JSON_KEY_DATE        = '\x09'
	JSON_KEY_TIME        = '\x0A'
	JSON_KEY_DATETIME    = '\x0B'
	JSON_KEY_OPAQUE      = '\x0C'
)
View Source
const MaxDepth = 300

MaxDepth is the maximum depth for nested JSON.

Variables

View Source
var (
	ValueTrue  = &Value{t: TypeBoolean}
	ValueFalse = &Value{t: TypeBoolean}
	ValueNull  = &Value{t: TypeNull}
)

Functions

func ApplyTransform

func ApplyTransform(t Transformation, doc *Value, paths []*Path, values []*Value) error

func MarshalSQLValue

func MarshalSQLValue(buf []byte) (*sqltypes.Value, error)

MarshalSQLValue converts the byte representation of a json value and returns it formatted by MarshalSQLTo

func MatchPath

func MatchPath(rawJSON, rawPath []byte, match func(value *Value)) error

Types

type NumberType

type NumberType int32
const (
	NumberTypeUnknown NumberType = iota
	NumberTypeSigned
	NumberTypeUnsigned
	NumberTypeDecimal
	NumberTypeFloat
)

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object represents JSON object.

Object cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.

func (*Object) Add

func (o *Object) Add(key string, value *Value)

func (*Object) CachedSize

func (cached *Object) CachedSize(alloc bool) int64

func (*Object) Del

func (o *Object) Del(key string)

Del deletes the entry with the given key from o.

func (*Object) Get

func (o *Object) Get(key string) *Value

Get returns the value for the given key in the o.

Returns nil if the value for the given key isn't found.

The returned value is valid until Parse is called on the Parser returned o.

func (*Object) Keys

func (o *Object) Keys() []string

func (*Object) Len

func (o *Object) Len() int

Len returns the number of items in the o.

func (*Object) MarshalTo

func (o *Object) MarshalTo(dst []byte) []byte

MarshalTo appends marshaled o to dst and returns the result.

func (*Object) Set

func (o *Object) Set(key string, value *Value, t Transformation)

Set sets (key, value) entry in the o.

The value must be unchanged during o lifetime.

func (*Object) String

func (o *Object) String() string

String returns string representation for the o.

This function is for debugging purposes only. It isn't optimized for speed. See MarshalTo instead.

func (*Object) Visit

func (o *Object) Visit(f func(key string, v *Value))

Visit calls f for each item in the o in the original order of the parsed JSON.

f cannot hold key and/or v after returning.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses JSON.

Parser may be re-used for subsequent parsing.

Parser cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.

func (*Parser) Parse

func (p *Parser) Parse(s string) (*Value, error)

Parse parses s containing JSON.

The returned value is valid until the next call to Parse*.

Use Scanner if a stream of JSON values must be parsed.

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(b []byte) (*Value, error)

ParseBytes parses b containing JSON.

The returned Value is valid until the next call to Parse*.

Use Scanner if a stream of JSON values must be parsed.

type Path

type Path struct {
	// contains filtered or unexported fields
}

func (*Path) ContainsWildcards

func (jp *Path) ContainsWildcards() bool

func (*Path) Match

func (jp *Path) Match(doc *Value, wrap bool, match func(value *Value))

func (*Path) String

func (jp *Path) String() string

type PathParser

type PathParser struct {
	// contains filtered or unexported fields
}

func (*PathParser) ParseBytes

func (p *PathParser) ParseBytes(in []byte) (*Path, error)

type Transformation

type Transformation int
const (
	Set Transformation = iota
	Insert
	Replace
	Remove
)

type Type

type Type int32

Type represents JSON type.

const (
	// TypeNull is JSON null.
	TypeNull Type = iota

	// TypeNumber is JSON number type.
	TypeNumber

	// TypeString is JSON string type.
	TypeString

	// TypeObject is JSON object type.
	TypeObject

	// TypeArray is JSON array type.
	TypeArray

	// TypeBoolean is JSON boolean.
	TypeBoolean

	// TypeDate is JSON date.
	TypeDate

	// TypeTime is JSON time.
	TypeTime

	// TypeDateTime is JSON time.
	TypeDateTime

	// TypeOpaque is JSON opaque type.
	TypeOpaque

	// TypeBit is JSON bit string.
	TypeBit

	// TypeBlob is JSON blob.
	TypeBlob
)

See https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison for the ordering here

func (Type) String

func (t Type) String() string

String returns string representation of t.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represents any JSON value.

Call Type in order to determine the actual type of the JSON value.

Value cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.

func NewArray

func NewArray(vals []*Value) *Value

func NewBit

func NewBit(raw string) *Value

func NewBlob

func NewBlob(raw string) *Value

func NewDate

func NewDate(raw string) *Value

func NewDateTime

func NewDateTime(raw string) *Value

func NewFromSQL added in v0.18.0

func NewFromSQL(v sqltypes.Value) (*Value, error)

func NewNumber

func NewNumber(num string, n NumberType) *Value

func NewObject

func NewObject(obj Object) *Value

func NewOpaqueValue

func NewOpaqueValue(raw string) *Value

func NewString

func NewString(raw string) *Value

func NewTime

func NewTime(raw string) *Value

func (*Value) Array

func (v *Value) Array() ([]*Value, bool)

Array returns the underlying JSON array for the v.

func (*Value) Bool

func (v *Value) Bool() (bool, bool)

Bool returns the underlying JSON bool for the v.

Use GetBool if you don't need error handling.

func (*Value) CachedSize

func (cached *Value) CachedSize(alloc bool) int64

func (*Value) Date

func (v *Value) Date() (datetime.Date, bool)

func (*Value) DateTime

func (v *Value) DateTime() (datetime.DateTime, bool)

func (*Value) Decimal

func (v *Value) Decimal() (decimal.Decimal, bool)

func (*Value) DelArrayItem

func (v *Value) DelArrayItem(n int)

func (*Value) Depth

func (v *Value) Depth() int

func (*Value) Float64

func (v *Value) Float64() (float64, bool)

func (*Value) Hash

func (v *Value) Hash(h *vthash.Hasher)

func (*Value) Int64

func (v *Value) Int64() (int64, bool)

func (*Value) Len

func (v *Value) Len() int

func (*Value) MarshalDate

func (v *Value) MarshalDate() string

func (*Value) MarshalDateTime

func (v *Value) MarshalDateTime() string

func (*Value) MarshalSQLTo

func (v *Value) MarshalSQLTo(dst []byte) []byte

MarshalSQLTo appends marshaled v to dst and returns the result in the form like `JSON_OBJECT` or `JSON_ARRAY` to ensure we don't lose any type information.

func (*Value) MarshalTime

func (v *Value) MarshalTime() string

func (*Value) MarshalTo

func (v *Value) MarshalTo(dst []byte) []byte

MarshalTo appends marshaled v to dst and returns the result.

func (*Value) NumberType

func (v *Value) NumberType() NumberType

func (*Value) Object

func (v *Value) Object() (*Object, bool)

Object returns the underlying JSON object for the v.

func (*Value) Raw

func (v *Value) Raw() string

func (*Value) SQLType

func (v *Value) SQLType() sqltypes.Type

func (*Value) SetArrayItem

func (v *Value) SetArrayItem(idx int, value *Value, t Transformation)

SetArrayItem sets the value in the array v at idx position.

The value must be unchanged during v lifetime.

func (*Value) String

func (v *Value) String() string

String returns string representation of the v.

The function is for debugging purposes only. It isn't optimized for speed. See MarshalTo instead.

Don't confuse this function with StringBytes, which must be called for obtaining the underlying JSON string for the v.

func (*Value) StringBytes

func (v *Value) StringBytes() ([]byte, bool)

StringBytes returns the underlying JSON string for the v.

func (*Value) Time

func (v *Value) Time() (datetime.Time, bool)

func (*Value) ToBoolean

func (v *Value) ToBoolean() bool

func (*Value) ToRawBytes

func (v *Value) ToRawBytes() []byte

func (*Value) ToUnencodedBytes

func (v *Value) ToUnencodedBytes() []byte

func (*Value) Type

func (v *Value) Type() Type

Type returns the type of the v.

func (*Value) Uint64

func (v *Value) Uint64() (uint64, bool)

func (*Value) WeightString added in v0.18.0

func (v *Value) WeightString(dst []byte) []byte

Jump to

Keyboard shortcuts

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