Current section
Files
Jump to
Current section
Files
README.md
**`Ecto.JSON`** makes `Ecto` able to use any type of data (Integer, String, List, Map, etc.) which is valid JSON, not only key-value maps.
[](https://hex.pm/packages/ecto_json)
[](https://hexdocs.pm/ecto_json)
[](https://hex.pm/packages/ecto_json)
[](https://github.com/ertgl/ecto_json)
[](LICENSE.txt)
**`Installation`**
The package is [available in Hex](https://hex.pm/packages/ecto_json), it can be installed
by adding `:ecto_json` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ecto_json, "~> 0.1.0"},
]
end
```
**`Usage`**
The package is [available in Hex](https://hex.pm/packages/ecto_json), it can be installed
by adding `:ecto_json` to your list of dependencies in `mix.exs`:
```elixir
defmodule Property do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "properties" do
field :key, :string
field :value, Ecto.JSON
timestamps([
type: :utc_datetime,
])
end
def changeset(property, attrs) do
property
|> cast(attrs, [:key, :value])
|> validate_required([:key, :value])
end
end
```