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

Function arrayToJsonPretty

server/functions/array_to_json.go:122–138  ·  view source on GitHub ↗

arrayToJsonPretty produces a pretty-printed JSON array where dimension-1 elements are separated by a comma and newline.

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

Source from the content-addressed store, hash-verified

120// arrayToJsonPretty produces a pretty-printed JSON array where dimension-1 elements are
121// separated by a comma and newline.
122func arrayToJsonPretty(ctx *sql.Context, arrType *pgtypes.DoltgresType, arr []any) (string, error) {
123 baseType := arrType.ArrayBaseType()
124 sb := strings.Builder{}
125 sb.WriteRune('[')
126 for i, el := range arr {
127 if i > 0 {
128 sb.WriteString(",\n ")
129 }
130 raw, err := valueToJsonRaw(ctx, baseType, el)
131 if err != nil {
132 return "", err
133 }
134 sb.Write(raw)
135 }
136 sb.WriteRune(']')
137 return sb.String(), nil
138}

Callers 1

array_to_json.goFile · 0.85

Calls 5

valueToJsonRawFunction · 0.85
ArrayBaseTypeMethod · 0.80
WriteStringMethod · 0.80
StringMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected