{"record":{"id":"1f13da7eed032c6b","repo":"apache/beam","slug":"the-schema-is-not-a-valid-object-schema-n-s","errorCode":null,"errorMessage":"The schema is not a valid object schema:%n %s","messagePattern":"The schema is not a valid object schema:%n (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JsonUtils.java","lineNumber":315,"sourceCode":"      if (((ArraySchema) propertySchema).getAllItemSchema() == null) {\n        throw new IllegalArgumentException(\n            \"Array schema is not properly formatted or unsupported (\"\n                + propertySchema\n                + \"). Note that JSON-schema's tuple-like arrays are not supported by Beam.\");\n      }\n      return Schema.FieldType.array(\n          beamTypeFromJsonSchemaType(((ArraySchema) propertySchema).getAllItemSchema()));\n    } else {\n      throw new IllegalArgumentException(\"Unsupported schema type: \" + propertySchema.getClass());\n    }\n  }\n\n  private static org.everit.json.schema.ObjectSchema jsonSchemaFromString(String jsonSchema) {\n    JSONObject parsedSchema = new JSONObject(jsonSchema);\n    org.everit.json.schema.Schema schemaValidator =\n        org.everit.json.schema.loader.SchemaLoader.load(parsedSchema);\n    if (!(schemaValidator instanceof ObjectSchema)) {\n      throw new IllegalArgumentException(\n          String.format(\"The schema is not a valid object schema:%n %s\", jsonSchema));\n    }\n    return (org.everit.json.schema.ObjectSchema) schemaValidator;\n  }\n\n  private abstract static class JsonToRowFn<T> extends SimpleFunction<T, Row> {\n    final RowJson.RowJsonDeserializer deserializer;\n    final ObjectMapper objectMapper;\n\n    private JsonToRowFn(Schema beamSchema) {\n      deserializer = RowJson.RowJsonDeserializer.forSchema(beamSchema);\n      objectMapper = RowJsonUtils.newObjectMapperWith(deserializer);\n    }\n  }\n\n  private abstract static class RowToJsonFn<T> extends SimpleFunction<Row, T> {\n    final RowJson.RowJsonSerializer serializer;\n    final ObjectMapper objectMapper;","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JsonUtils.java#L297-L333","documentation":"jsonSchemaFromString loads a JSON Schema document via org.everit.json.schema SchemaLoader and requires the result to be an ObjectSchema (a top-level 'type': 'object' schema), because JsonUtils builds Beam Rows from object schemas. If the loaded schema is any other type (string, array, boolean, number schema), it throws this IllegalArgumentException containing the offending schema text.","triggerScenarios":"Calling JsonUtils.jsonSchema(jsonSchema) / JsonUtils.jsonRowsToRows with a top-level schema like {\"type\": \"string\"}, {\"type\": \"array\", ...}, or a bare true/false schema; the loaded validator is not an ObjectSchema.","commonSituations":"Users pass a schema describing individual values rather than records, accidentally nest the object definition under 'properties' or 'definitions' at the wrong level, or copy a schema fragment instead of the whole object schema.","solutions":["Make the top-level JSON Schema an object schema: {\"type\": \"object\", \"properties\": {...}}.","If your data is an array of records, define the element schema as the object schema and let JsonUtils handle the array wrapper (jsonRowsToRows expects a top-level array of objects matching this schema).","Verify the schema parses as an object by loading it with org.everit.json.schema.loader.SchemaLoader yourself before calling JsonUtils."],"exampleFix":"// before\nString schema = \"{\\\"type\\\": \\\"array\\\", \\\"items\\\": {\\\"type\\\": \\\"object\\\", ...}}\";\n// after\nString schema = \"{\\\"type\\\": \\\"object\\\", \\\"properties\\\": {\\\"id\\\": {\\\"type\\\": \\\"integer\\\"}}}\";","handlingStrategy":"validation","validationCode":"org.everit.json.schema.Schema loaded =\n    org.everit.json.schema.loader.SchemaLoader.load(new JSONObject(jsonSchemaString));\nif (!(loaded instanceof org.everit.json.schema.ObjectSchema)) {\n  throw new IllegalArgumentException(\"Top-level schema must be {\\\"type\\\": \\\"object\\\", ...}\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  JsonUtils.jsonSchema(jsonSchemaString);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"not a valid object schema\")) {\n    // wrap the schema: {\"type\":\"object\",\"properties\":{\"value\": <original>}}\n  } else throw e;\n}","preventionTips":["Always define the record schema itself at the top level, not the array or the value schema.","Unit-test schema strings with SchemaLoader before wiring them into pipelines.","Keep schema fragments in 'definitions' and reference them inside a top-level object schema."],"tags":["java","json-schema","beam-schema"],"backgroundTag":"schema-validation-failed","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"}