# Export as JSON

`EventSchemaJsonWriter` serialises an `IEventSchema` to a JSON stream. It is included in the `Hermodr.Schema` package — no extra installation required.

## Usage

```csharp
using Hermodr;
using System.Text.Json;

var schema = EventSchema.FromDataType<OrderPlacedData>();

var writer = new EventSchemaJsonWriter(new JsonWriterOptions { Indented = true });

await using var stream = File.OpenWrite("order-placed-schema.json");
await writer.WriteToAsync(stream, schema);
```

## `JsonWriterOptions`

Pass a `System.Text.Json.JsonWriterOptions` instance to control formatting:

| Option     | Default | Effect                       |
| ---------- | ------- | ---------------------------- |
| `Indented` | `false` | Pretty-print the JSON output |
| `Encoder`  | `null`  | Custom character encoder     |

## Output format

```json
{
  "type": "order.placed",
  "version": "1.0",
  "contentType": "object",
  "description": "Raised when a customer places an order",
  "properties": {
    "OrderId": {
      "dataType": "guid",
      "required": true
    },
    "Amount": {
      "dataType": "money",
      "required": true,
      "min": 0.01,
      "max": 1000000
    },
    "Currency": {
      "dataType": "string",
      "required": true
    },
    "Notes": {
      "dataType": "string",
      "nullable": true
    }
  }
}
```

## Writing to a string

```csharp
await using var memStream = new MemoryStream();
await writer.WriteToAsync(memStream, schema);
var json = Encoding.UTF8.GetString(memStream.ToArray());
```

## `IEventSchemaWriter` interface

`EventSchemaJsonWriter` implements `IEventSchemaWriter`:

```csharp
public interface IEventSchemaWriter
{
    Task WriteToAsync(Stream stream, IEventSchema schema, CancellationToken cancellationToken = default);
}
```

You can register and resolve it via DI if you prefer not to instantiate it directly.

## Related pages

* [Export as YAML](/event-schema/export-yaml.md)
* [Export as AsyncAPI](/event-schema/export-asyncapi.md)
* [Fluent Builder](/event-schema/fluent-builder.md)
* [From Annotations](/event-schema/from-annotations.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hermodr.deveel.org/event-schema/export-json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
