Skip to content

Blazer is a case parser for maps and JSON keys using NIFs.

License

Notifications You must be signed in to change notification settings

hammsvietro/blazer

Repository files navigation

Blazer

Blazer is a fast case parser for maps, strings and JSON using NIFs.

Useful to consume camel/pascal cased APIs while still using elixir's snake case convention

Uses Jason to parse the json data.

Documentation

Installation

It can be installed by adding blazer to your list of dependencies in mix.exs:

def deps do
  [
    {:blazer, "~> 0.1.1"}
  ]
end

Basic Usage

iex(1)> Blazer.parse(%{"categoryId" => 13, "profileName" => "hammsvietro"}, case: :snake)
{:ok, %{category_id: 13, profile_name: "hammsvietro"}}


iex(2)> Jason.encode!(%{"category_id" => 13, "profile_name" => "hammsvietro"}, case: :camel))
"{\"categoryId\":13,\"profileName\":\"hammsvietro\"}"

Usage with Phoenix

In your config.exs:

config :blazer, inner_case: :snake, outer_case: :camel
config :phoenix, :json_library, Blazer

There you go! Now every map key will use elixir's standard snake case while externally the API will produce/consume camel cased properties

Contributing

Contributions are very welcome! Feel free to open an issue =)

License

Blazer source code is licensed under the MIT License.

About

Blazer is a case parser for maps and JSON keys using NIFs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published