Flat JSON

Decode string with flat JSON to a Map

Support Elixir & ElixirScript

Algorithm

def parse(s) do
  s
  |> String.replace_leading("{", "")
  |> String.replace_trailing("}", "")
  |> String.replace("\"", "")
  |> String.split(",")
  |> Enum.map(fn (p) -> String.split(p, ":") end)
  |> Map.new(fn [key, value] -> {key, value} end)
end

Installation

The package can be installed by adding flat_json to your list of dependencies in mix.exs:

def deps do
  [
    {:flat_json, git: "git://github.com/flat-json/flat-json.git"}
  ]
end

Usage

iex(1)> ~s({"key":"value"}) |> FlatJSON.parse
%{"key" => "value"}