-
Notifications
You must be signed in to change notification settings - Fork 120
Description
When validating JSON data, arrays of concrete Go types such as []string or []map[string]interface{} are rejected with errors like:
invalid jsonType []string
invalid jsonType []map[string]interface {}
This occurs even though these slice types serialize correctly to JSON arrays and match schemas such as:
{
"type": "array",
"items": { "type": "string" }
}Expected behavior:
Slices of concrete types ([]string, []int, []map[string]interface{}, etc.) should be accepted as valid JSON arrays without needing to convert to []any.
Actual behavior:
Validation fails unless the data is explicitly converted to []any before validation.
Example:
schema := `{
"type": "object",
"properties": {
"interfaces": {
"type": "array",
"items": { "type": "string" }
}
}
}`
values := map[string]any{
"interfaces": []string{"eth0", "eth1"},
}Produces:
at '/interfaces': invalid jsonType []string
Casting fixes it:
values := map[string]any{
"interfaces": []any{"eth0", "eth1"},
}It feels counterintuitive that the validator requires explicit conversion to []any for slices that are already valid JSON representations. This diverges from Go’s standard encoding/json behavior, where []string is directly encoded as a JSON array of strings.
Question:
Is this strict requirement for []any intended, or a limitation of how the validator performs type reflection on slices around here?