

# Creating a schema from event JSON in Amazon EventBridge
<a name="eb-schemas-infer-from-json"></a>

If you have the JSON of an event, you can automatically create a schema for that type of event.

**To create a schema based on the JSON of an event**

1. Open the Amazon EventBridge console at [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/).

1. In the navigation pane, choose **Schemas** and then choose **Create schema**.

1. (Optional) Select or create a schema registry.

1. Under **Schema details** enter a name for your schema.

1. (Optional) Enter a description for the schema you created.

1. For **Schema type**, choose **OpenAPI 3.0**.

   You can't use JSONSchema when you create a schema from the JSON of an event.

1. Select **Discover from JSON**

1. In the text box under **JSON**, paste or drag the JSON source of an event.

   For example, you could paste in the source from this AWS Step Functions event for a failed execution.

   ```
   {
       "version": "0",
       "id": "315c1398-40ff-a850-213b-158f73e60175",
       "detail-type": "Step Functions Execution Status Change",
       "source": "aws.states",
       "account": "012345678912",
       "time": "2019-02-26T19:42:21Z",
       "region": "us-east-1",
       "resources": [
         "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name"
       ],
       "detail": {
           "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name",
           "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine",
           "name": "execution-name",
           "status": "FAILED",
           "startDate": 1551225146847,
           "stopDate": 1551225151881,
           "input": "{}",
           "output": null
       }
   }
   ```

1. Choose **Discover schema**.

1. EventBridge generates an OpenAPI schema for the event. For example, the following schema is generated for the preceding Step Functions event.

   ```
   {
     "openapi": "3.0.0",
     "info": {
       "version": "1.0.0",
       "title": "StepFunctionsExecutionStatusChange"
     },
     "paths": {},
     "components": {
       "schemas": {
         "AWSEvent": {
           "type": "object",
           "required": ["detail-type", "resources", "detail", "id", "source", "time", "region", "version", "account"],
           "x-amazon-events-detail-type": "Step Functions Execution Status Change",
           "x-amazon-events-source": "aws.states",
           "properties": {
             "detail": {
               "$ref": "#/components/schemas/StepFunctionsExecutionStatusChange"
             },
             "account": {
               "type": "string"
             },
             "detail-type": {
               "type": "string"
             },
             "id": {
               "type": "string"
             },
             "region": {
               "type": "string"
             },
             "resources": {
               "type": "array",
               "items": {
                 "type": "string"
               }
             },
             "source": {
               "type": "string"
             },
             "time": {
               "type": "string",
               "format": "date-time"
             },
             "version": {
               "type": "string"
             }
           }
         },
         "StepFunctionsExecutionStatusChange": {
           "type": "object",
           "required": ["output", "input", "executionArn", "name", "stateMachineArn", "startDate", "stopDate", "status"],
           "properties": {
             "executionArn": {
               "type": "string"
             },
             "input": {
               "type": "string"
             },
             "name": {
               "type": "string"
             },
             "output": {},
             "startDate": {
               "type": "integer",
               "format": "int64"
             },
             "stateMachineArn": {
               "type": "string"
             },
             "status": {
               "type": "string"
             },
             "stopDate": {
               "type": "integer",
               "format": "int64"
             }
           }
         }
       }
     }
   }
   ```

1. After the schema has been generated, choose **Create**.