Skip to content

Validation fails for []string and []map[string]interface{} unless explicitly cast to []any #238

@bschimke95

Description

@bschimke95

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions