# `Apical.ToJson`
[🔗](https://github.com/E-xyza/Apical/blob/main/lib/apical/to_json.ex#L1)

Protocol for converting Apical errors to JSON-compatible maps.

This protocol provides a consistent way to convert Apical exceptions
to maps that can be easily serialized to JSON for API error responses.

## Example

    error = %Apical.Exceptions.ParameterError{
      operation_id: "getUser",
      in: :path,
      reason: "required parameter `id` not present"
    }

    json_map = Apical.ToJson.to_json(error)
    # => %{
    #   error: "parameter_error",
    #   status: 400,
    #   operation_id: "getUser",
    #   location: "path",
    #   message: "Parameter Error in operation getUser (in path): ..."
    # }

    Jason.encode!(json_map)
    # => "{"error":"parameter_error","status":400,...}"

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `to_json`

```elixir
@spec to_json(t()) :: map()
```

Converts an Apical exception to a JSON-compatible map.

Returns a map with at minimum:
- `:error` - A string identifier for the error type
- `:status` - The HTTP status code
- `:message` - A human-readable error message

Additional fields may be included depending on the error type.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
