MCPcopy Create free account
hub / github.com/dolthub/doltgresql / arrayToJsonRaw

Function arrayToJsonRaw

server/functions/array_to_json.go:74–85  ·  view source on GitHub ↗

arrayToJsonRaw converts an anyarray to a JSON byte slice.

(ctx *sql.Context, arrType *pgtypes.DoltgresType, arr []any)

Source from the content-addressed store, hash-verified

72
73// arrayToJsonRaw converts an anyarray to a JSON byte slice.
74func arrayToJsonRaw(ctx *sql.Context, arrType *pgtypes.DoltgresType, arr []any) (json.RawMessage, error) {
75 baseType := arrType.ArrayBaseType()
76 elements := make([]json.RawMessage, len(arr))
77 for i, el := range arr {
78 raw, err := valueToJsonRaw(ctx, baseType, el)
79 if err != nil {
80 return nil, err
81 }
82 elements[i] = raw
83 }
84 return json.Marshal(elements)
85}
86
87// valueToJsonRaw converts a single value to a JSON byte slice.
88func valueToJsonRaw(ctx *sql.Context, elemType *pgtypes.DoltgresType, val any) (json.RawMessage, error) {

Callers 2

array_to_json.goFile · 0.85
valueToJsonRawFunction · 0.85

Calls 3

valueToJsonRawFunction · 0.85
ArrayBaseTypeMethod · 0.80
MarshalMethod · 0.45

Tested by

no test coverage detected