Configuration options
int64
default:"1048576"
Maximum size of the JSON value in bytes (up to 2^53-1). Defaults to 1MB if not set or zero.
bool
default:"false"
When true, requires the field value to be non-empty JSON (not null, empty string, empty array, or empty object).
Validation rules
The json field validates:- JSON syntax: Value must be valid JSON
- Size: JSON string size must not exceed
maxSizebytes - Required: If enabled, value cannot be null,
"",[], or{}
Value normalization
When submitting plain string values (e.g., from multipart/form-data), the following normalization rules apply:"true"→true"false"→false"null"→null- Numeric strings → JSON numbers
- Valid JSON strings starting with
[,{, or"→ parsed as JSON - Other strings → double-quoted JSON strings
- Empty string →
""
This normalization allows the field to work seamlessly with both JSON and multipart/form-data request formats.
Go examples
- Basic usage
- With size limit
- Array values
- Complex nested data
Database column type
Working with JSON values
Common use cases
Querying JSON fields
You can query JSON fields using JSONPath-like syntax:Best practices
- Set appropriate
maxSizeto prevent database bloat and performance issues - Use structured field types (text, number, etc.) when possible for better queryability
- JSON fields are great for flexible, schemaless data that varies by record
- Consider indexing frequently queried JSON properties
- Validate JSON structure in your application layer for complex schemas
- Be mindful that JSON fields consume more storage than primitive types
Empty vs null
Whenrequired: true, these values are considered empty and will fail validation:
null""[]{}
Zero value
The zero value for json fields is a zerotypes.JSONRaw.