# Zoi
[](https://github.com/phcurado/zoi/actions/workflows/ci.yml)
[](https://coveralls.io/github/phcurado/zoi?branch=main)
[](https://hex.pm/packages/zoi)
[](https://hexdocs.pm/zoi)
[](https://hex.pm/packages/zoi)
`Zoi` is a schema validation library for Elixir, designed to provide a simple and flexible way to define and validate data.
## Installation
`zoi` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:zoi, "~> 0.2"}
]
end
```
## Usage
You can define schemas and validate data against them. Schemas can be used to validate maps, lists or primitive types such as strings, integers, etc.
```elixir
# Define a schema with primitive type
schema = Zoi.string() |> Zoi.min(3)
Zoi.parse(schema, "hello") # {:ok, "hello"}
schema = Zoi.string() |> Zoi.trim()
Zoi.parse(schema, " world ") # {:ok, "world"}
# Validate a structured data in a map
schema = Zoi.object(%{name: Zoi.string(), age: Zoi.integer(), email: Zoi.string() |> Zoi.email()})
Zoi.parse(schema, %{name: "John", age: 30, email: "john@email.com"})
# {:ok, %{name: "John", age: 30, email: "john@email.com"}}
Zoi.parse(schema, %{email: "invalid-email"})
#{:error, [
# %Zoi.Error{path: [:name], message: "is required"},
# %Zoi.Error{path: [:age], message: "is required"},
# %Zoi.Error{path: [:email], message: "invalid email format"}
# ]
#}
```
And many more possibilities, including nested schemas, custom validations and data transformations. Check the official [docs](https://hexdocs.pm/zoi) for more details.
## Acknowledgements
`Zoi` is inspired by [Zod](https://zod.dev/) and [Joi](https://joi.dev/), providing a similar experience for Elixir.