Documentation ¶
Index ¶
- Variables
- func CompareJSON(j1 JSON, j2 JSON) (cmp int, err error)
- func PeekBytesAsJSON(b []byte) (n int, err error)
- func Serialize(j JSON) []byte
- type JSON
- func (j JSON) Extract(pathExprList []PathExpression) (ret JSON, found bool)
- func (j JSON) MarshalJSON() ([]byte, error)
- func (j JSON) Merge(suffixes []JSON) JSON
- func (j JSON) Modify(pathExprList []PathExpression, values []JSON, mt ModifyType) (retj JSON, err error)
- func (j JSON) Remove(pathExprList []PathExpression) (JSON, error)
- func (j JSON) String() string
- func (j JSON) Type() string
- func (j *JSON) UnmarshalJSON(data []byte) (err error)
- func (j JSON) Unquote() (string, error)
- type ModifyType
- type PathExpression
- type TypeCode
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidJSONText means invalid JSON text. ErrInvalidJSONText = terror.ClassJSON.New(mysql.ErrInvalidJSONText, mysql.MySQLErrName[mysql.ErrInvalidJSONText]) // ErrInvalidJSONPath means invalid JSON path. ErrInvalidJSONPath = terror.ClassJSON.New(mysql.ErrInvalidJSONPath, mysql.MySQLErrName[mysql.ErrInvalidJSONPath]) // ErrInvalidJSONData means invalid JSON data. ErrInvalidJSONData = terror.ClassJSON.New(mysql.ErrInvalidJSONData, mysql.MySQLErrName[mysql.ErrInvalidJSONData]) )
Functions ¶
func CompareJSON ¶
CompareJSON compares two json objects. Returns -1 if j1 < j2, 0 if j1 == j2, else returns 1.
func PeekBytesAsJSON ¶
PeekBytesAsJSON trys to peek some bytes from b, until we can deserialize a JSON from those bytes.
Types ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON is for MySQL JSON type.
func CreateJSON ¶
func CreateJSON(in interface{}) JSON
CreateJSON creates a JSON from in. Panic if any error occurs.
func Deserialize ¶
Deserialize means deserialize a json from bytes.
func ParseFromString ¶
ParseFromString parses a json from string.
func (JSON) Extract ¶
func (j JSON) Extract(pathExprList []PathExpression) (ret JSON, found bool)
Extract receives several path expressions as arguments, matches them in j, and returns:
ret: target JSON matched any path expressions. maybe autowrapped as an array. found: true if any path expressions matched.
func (JSON) MarshalJSON ¶
MarshalJSON implements Marshaler interface.
func (JSON) Merge ¶
Merge merges suffixes into j according the following rules: 1) adjacent arrays are merged to a single array; 2) adjacent object are merged to a single object; 3) a scalar value is autowrapped as an array before merge; 4) an adjacent array and object are merged by autowrapping the object as an array.
func (JSON) Modify ¶
func (j JSON) Modify(pathExprList []PathExpression, values []JSON, mt ModifyType) (retj JSON, err error)
Modify modifies a JSON object by insert, replace or set. All path expressions cannot contain * or ** wildcard. If any error occurs, the input won't be changed.
func (JSON) Remove ¶
func (j JSON) Remove(pathExprList []PathExpression) (JSON, error)
Remove removes the elements indicated by pathExprList from JSON.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface.
type ModifyType ¶
type ModifyType byte
ModifyType is for modify a JSON. There are three valid values: ModifyInsert, ModifyReplace and ModifySet.
const ( // ModifyInsert is for insert a new element into a JSON. ModifyInsert ModifyType = 0x01 // ModifyReplace is for replace an old elemList from a JSON. ModifyReplace ModifyType = 0x02 // ModifySet = ModifyInsert | ModifyReplace ModifySet ModifyType = 0x03 )
type PathExpression ¶
type PathExpression struct {
// contains filtered or unexported fields
}
PathExpression is for JSON path expression.
func ParseJSONPathExpr ¶
func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error)
ParseJSONPathExpr parses a JSON path expression. Returns a PathExpression object which can be used in JSON_EXTRACT, JSON_SET and so on.