apache/beam · error · ValueError

Expected object type, got

Error message

Expected object type, got {json_type}.

What it means

json_schema_to_beam_schema converts a JSON Schema into a Beam schema, but only handles top-level object schemas. If the schema's 'type' field is anything other than 'object' (or absent), it raises ValueError. JSON schemas describing arrays, strings, or numbers at the root are not supported for Beam row conversion.

Solutions

  1. Wrap the schema in an object: {"type":"object","properties":{"items":{"type":"array","items":<your schema>}}}]
  2. Set json_schema['type'] to 'object' and define its 'properties'
  3. Verify you are passing the whole record schema, not a nested field's schema

Example fix

// before
{"type": "array", "items": {"type": "string"}}
// after
{"type": "object", "properties": {"items": {"type": "array", "items": {"type": "string"}}}}
Defensive patterns

Strategy: validation

Validate before calling

def assert_root_object_schema(json_schema):
    if not isinstance(json_schema, dict) or json_schema.get('type') != 'object':
        raise ValueError('Root JSON schema must be {"type": "object", ...}')

Type guard

def is_object_schema(s) -> bool:
    return isinstance(s, dict) and s.get('type') == 'object'

Try / catch

try:
    beam_schema = json_schema_to_beam_schema(json_schema)
except ValueError as e:
    raise ValueError(f'Invalid root JSON schema for Beam conversion: {e}') from e

Prevention

When it happens

Trigger: Passing a JSON schema dict whose json_schema['type'] is not exactly 'object' (e.g. 'array', 'string', or missing) to json_schema_to_beam_schema, typically via json_type_to_beam_type or the yaml json_schema option of transforms like ReadFromJson/WriteToJson.

Common situations: Feeding a root-level array or primitive JSON schema meant for the payload itself rather than the row; copying a schema fragment (e.g. an item schema of an array) instead of the wrapping object schema; typo like 'typo': 'object' leaving 'type' unset.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/72dee1b46ff8436e. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/yaml/json_utils.py:66

    schema_pb2.FLOAT: 'number',
    **{
        v: k
        for k, v in JSON_ATOMIC_TYPES_TO_BEAM.items()
    }
}


def json_schema_to_beam_schema(
    json_schema: dict[str, Any]) -> schema_pb2.Schema:
  """Returns a Beam schema equivalent for the given Json schema."""
  def maybe_nullable(beam_type, nullable):
    if nullable:
      beam_type.nullable = True
    return beam_type

  json_type = json_schema.get('type', None)
  if json_type != 'object':
    raise ValueError(f'Expected object type, got {json_type}.')
  if 'properties' not in json_schema:
    # Technically this is a valid (vacuous) schema, but as it's not generally
    # meaningful, throw an informative error instead.
    # (We could add a flag to allow this degenerate case.)
    raise ValueError('Missing properties for {json_schema}.')
  required = set(json_schema.get('required', []))
  return schema_pb2.Schema(
      fields=[
          schemas.schema_field(
              name,
              maybe_nullable(json_type_to_beam_type(t), name not in required),
              description=t.get('description') if isinstance(t, dict) else None)
          for (name, t) in json_schema['properties'].items()
      ])


def json_type_to_beam_type(json_type: dict[str, Any]) -> schema_pb2.FieldType:
  """Returns a Beam schema type for the given Json (schema) type."""

View on GitHub (pinned to 12126d8942)