{"record":{"id":"861a5422a3d00360","repo":"apache/beam","slug":"missing-properties-for-json-schema","errorCode":null,"errorMessage":"Missing properties for {json_schema}.","messagePattern":"Missing properties for (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/json_utils.py","lineNumber":71,"sourceCode":"}\n\n\ndef json_schema_to_beam_schema(\n    json_schema: dict[str, Any]) -> schema_pb2.Schema:\n  \"\"\"Returns a Beam schema equivalent for the given Json schema.\"\"\"\n  def maybe_nullable(beam_type, nullable):\n    if nullable:\n      beam_type.nullable = True\n    return beam_type\n\n  json_type = json_schema.get('type', None)\n  if json_type != 'object':\n    raise ValueError(f'Expected object type, got {json_type}.')\n  if 'properties' not in json_schema:\n    # Technically this is a valid (vacuous) schema, but as it's not generally\n    # meaningful, throw an informative error instead.\n    # (We could add a flag to allow this degenerate case.)\n    raise ValueError('Missing properties for {json_schema}.')\n  required = set(json_schema.get('required', []))\n  return schema_pb2.Schema(\n      fields=[\n          schemas.schema_field(\n              name,\n              maybe_nullable(json_type_to_beam_type(t), name not in required),\n              description=t.get('description') if isinstance(t, dict) else None)\n          for (name, t) in json_schema['properties'].items()\n      ])\n\n\ndef json_type_to_beam_type(json_type: dict[str, Any]) -> schema_pb2.FieldType:\n  \"\"\"Returns a Beam schema type for the given Json (schema) type.\"\"\"\n  if not isinstance(json_type, dict) or 'type' not in json_type:\n    raise ValueError(f'Malformed type {json_type}.')\n  type_name = json_type['type']\n  if type_name in JSON_ATOMIC_TYPES_TO_BEAM:\n    return schema_pb2.FieldType(","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/json_utils.py#L53-L89","documentation":"json_schema_to_beam_schema rejects object JSON schemas that lack a 'properties' key. Although such a schema is technically valid JSON Schema (vacuously), it cannot be turned into a meaningful Beam row schema, so an informative ValueError is raised instead of producing an empty schema.","triggerScenarios":"Passing {\"type\":\"object\"} with no 'properties' (and no intent to use additionalProperties) to json_schema_to_beam_schema, e.g. an empty placeholder schema in a yaml pipeline config.","commonSituations":"Hand-written pipeline YAML where the json_schema option has type object but fields were never filled in; schemas generated from empty records; trimming fields to test and removing properties entirely.","solutions":["Add a 'properties' mapping listing the row's fields and their types","If the data is a free-form map, model it with \"additionalProperties\" (via json_type_to_beam_type) instead of an empty object","Validate the schema JSON before feeding it to the pipeline"],"exampleFix":"// before\n{\"type\": \"object\"}\n// after\n{\"type\": \"object\", \"properties\": {\"id\": {\"type\": \"integer\"}, \"name\": {\"type\": \"string\"}}}","handlingStrategy":"validation","validationCode":"def assert_properties_present(json_schema):\n    if json_schema.get('type') == 'object' and 'properties' not in json_schema:\n        raise ValueError('Object schema must define properties (or use additionalProperties at nested level)')","typeGuard":"def has_properties(s) -> bool:\n    return isinstance(s, dict) and 'properties' in s","tryCatchPattern":"try:\n    beam_schema = json_schema_to_beam_schema(json_schema)\nexcept ValueError as e:\n    if 'Missing properties' in str(e):\n        raise ValueError(f'Schema {json_schema!r} needs a properties mapping') from e\n    raise","preventionTips":["Never emit bare {\"type\":\"object\"}; always include at least one property","Fill in the json_schema section of yaml transforms completely, no placeholders","Lint pipeline YAML schemas for empty object definitions"],"tags":["python","apache-beam","json-schema","schema"],"backgroundTag":"missing-required-config-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}