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{})
| 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. |
| 863 | func 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. |