Documentation
¶
Overview ¶
Package jsontype provides a JSON wrapper type that round-trips correctly between Go, JSON, and SQL drivers (Postgres jsonb, MySQL json, SQLite TEXT).
JSON is a thin alias over json.RawMessage that implements:
- sql.Scanner / driver.Valuer for database round-tripping
- json.Marshaler / json.Unmarshaler so it serialises as raw JSON instead of the base64-encoded []byte the default would produce
- MarshalGQL / UnmarshalGQL for gqlgen scalar adapters (the methods are duck-typed; jsontype itself does not import gqlgen)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSON ¶
type JSON json.RawMessage
JSON is a json.RawMessage that round-trips through SQL drivers and gqlgen.
func From ¶
From marshals an arbitrary value into a *JSON. Convenient for passing arbitrary structures into a database column without manual marshalling.
func (JSON) MarshalGQL ¶
MarshalGQL writes the JSON bytes to w. Implements the gqlgen Marshaler interface (duck-typed; this package does not import gqlgen).
func (JSON) MarshalJSON ¶
MarshalJSON returns the raw JSON bytes without base64 encoding.
func (*JSON) Scan ¶
Scan implements database/sql.Scanner. It accepts []byte, string, or nil (mapped to the JSON null literal).
func (*JSON) UnmarshalGQL ¶
UnmarshalGQL parses an input from gqlgen — string, []byte, or map[string]any — into JSON.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON deserialises raw JSON bytes into JSON. Returns an error if the input is not valid JSON (json.RawMessage.UnmarshalJSON does not validate, so we wrap json.Valid for safer round-tripping).