# Insert String, Integer, Map, List in a jsonb PostgreSQL column

**URL:** <https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276>\
**Category:** Questions\
**Tags:** ecto, postgres\
**Created:** [January 10, 2019, 2:35pm UTC](https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276 "2019-01-10T14:35:06Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![mischov](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mischov/32/2489_2.png) [@mischov](https://forum.elixirforum.com/u/mischov)\
**Post date:** [January 11, 2019, 4:53pm UTC](https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/12 "2019-01-11T16:53:21Z")

</div>

Yeah, creating a type is a solution- something similar (but different) to this will likely work.

```elixir
defmodule Type.Json do
  @behaviour Ecto.Type
  @moduledoc """
  To store values that might be any json value.

  Not intended as a general replacement for :map.
  """

  def type, do: :json

  def cast(value) when is_nil(value), do: {:ok, value}
  def cast(value) when is_boolean(value), do: {:ok, value}
  def cast(value) when is_binary(value), do: {:ok, value}
  def cast(value) when is_number(value), do: {:ok, value}
  def cast(value) when is_list(value), do: {:ok, value}
  def cast(value) when is_map(value), do: {:ok, value}
  def cast(_), do: :error

  def load(data), do: {:ok, data}

  def dump(value) when is_nil(value), do: {:ok, value}
  def dump(value) when is_boolean(value), do: {:ok, value}
  def dump(value) when is_binary(value), do: {:ok, value}
  def dump(value) when is_number(value), do: {:ok, value}
  def dump(value) when is_list(value), do: {:ok, value}
  def dump(value) when is_map(value), do: {:ok, value}
  def dump(_), do: :error
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276)._
