jackc/pgx · error
jsonb too short
Error message
jsonb too short
What it means
The binary JSONB wire format prefixes every value with a one-byte version header. This guard fires when a non-NULL jsonb payload in binary format contains zero bytes, so there is no version byte to inspect — the source buffer is truncated below the minimum 1-byte length the format requires.
Solutions
- Treat this as data corruption: verify the column really holds jsonb and the binary format was requested correctly
- Use text format for the column instead of binary if the server/driver combination produces empty payloads
- Check for a truncated or misallocated buffer if the value was produced by custom encoding logic
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/jsonb.go:68 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /api/errors/79fc0a6966f4e08e.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/jsonb.go:68
}
case TextFormatCode:
return (&JSONCodec{Marshal: c.Marshal, Unmarshal: c.Unmarshal}).PlanScan(m, oid, format, target)
}
return nil
}
type scanPlanJSONBCodecBinaryUnwrapper struct {
textPlan ScanPlan
}
func (plan *scanPlanJSONBCodecBinaryUnwrapper) Scan(src []byte, dst any) error {
if src == nil {
return plan.textPlan.Scan(src, dst)
}
if len(src) == 0 {
return fmt.Errorf("jsonb too short")
}
if src[0] != 1 {
return fmt.Errorf("unknown jsonb version number %d", src[0])
}
return plan.textPlan.Scan(src[1:], dst)
}
func (c *JSONBCodec) DecodeDatabaseSQLValue(m *Map, oid uint32, format int16, src []byte) (driver.Value, error) {
if src == nil {
return nil, nil
}
switch format {
case BinaryFormatCode:
if len(src) == 0 {
return nil, fmt.Errorf("jsonb too short")View on GitHub (pinned to ec1a0befd2)