MCPcopy Create free account
hub / github.com/PostHog/duckgres / encodeJSON

Function encodeJSON

server/types.go:863–870  ·  view source on GitHub ↗

encodeJSON re-serializes a Go value to JSON bytes. The Go DuckDB driver deserializes JSON columns into native Go types (json.Unmarshal: string→string without quotes, object→map, array→slice, etc.). We must reverse this to produce valid JSON text for the wire protocol.

(v interface{})

Source from the content-addressed store, hash-verified

861// (json.Unmarshal: string→string without quotes, object→map, array→slice, etc.).
862// We must reverse this to produce valid JSON text for the wire protocol.
863func encodeJSON(v interface{}) []byte {
864 b, err := json.Marshal(v)
865 if err != nil {
866 // Fallback: encode as text (best effort)
867 return encodeText(v)
868 }
869 return b
870}
871
872// decodeBinary decodes binary-format parameter bytes based on type OID.
873// Returns (value, nil) on success, or (nil, error) for malformed data.

Callers 4

TestEncodeJSONFunction · 0.85
handleCopyOutMethod · 0.85
encodeBinaryFunction · 0.85

Calls 1

encodeTextFunction · 0.85

Tested by 1

TestEncodeJSONFunction · 0.68