Skip to content

json.schema() generates non-serializable default values #1182

Closed

Description

@vmphase

Description

msgspec.json.schema() puts a raw set() / bytearray() object into the schema's default for Struct fields using default_factory=set or default_factory=bytearray, so the result isn't json-serializable:

import json

import msgspec
from msgspec import field


class Config(msgspec.Struct):
    features: set[str] = field(default_factory=set)


json.dumps(msgspec.json.schema(Config))
# TypeError: Object of type set is not JSON serializable

I would expect the default to be a json value (e.g. []), like it already is for default_factory=list/dict.

Activity

  1. added a commit that references this issue on Sep 29, 2026
    c23e150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions