Convert amazon ion objects into elixir types

Here’s a quick and very dirty and unsafe implementation that works on your both samples:

defmodule CustomParser do
  def sample1(), do: "{subject:\"Elixir\",state:\"in use\",url:\"https://forum.elixirforum.com\",retrieved_on:2019-12-21T00:00:00.000000-00:00}"

  def sample2(), do: "{subject:\"Phoenix\",state:\"in use\",url:\"https://www.phoenixframework.org\",retrieved_on:2019-12-21T00:00:00.000000-00:00}"

  def parse(t) when is_binary(t) do
    t
    |> String.trim_leading("{")
    |> String.trim_trailing("}")
    |> String.split(",")
    |> Enum.map(fn(x) -> String.split(x, ":", parts: 2) end)
    |> Enum.map(fn([key, value]) -> {key, String.replace(value, "\"", "")} end)
    |> Map.new()
  end
end

Now test it in iex:

iex> CustomParser.parse(CustomParser.sample1())
%{
  "retrieved_on" => "2019-12-21T00:00:00.000000-00:00",
  "state" => "in use",
  "subject" => "Elixir",
  "url" => "https://forum.elixirforum.com"
}
iex> CustomParser.parse(CustomParser.sample2())
%{
  "retrieved_on" => "2019-12-21T00:00:00.000000-00:00",
  "state" => "in use",
  "subject" => "Phoenix",
  "url" => "https://www.phoenixframework.org"
}

I am not sure if this code properly assumes the shape of the input data though. The assumptions are shown in the hardcoded text samples.

From then on, you can additionally parse the date/times into proper Elixir objects. It’s pretty easy when you use timex.

I’d strongly recommend using something more proper like nimble_parsec for this task though!