4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Elixir Jason

Posted at

この記事ではelixirのJasonについて解説を行います。
ドキュメントを引用しつつJasonとは何なのかどういう機能があるのかを解説します。

Jason
公式ドキュメントからの引用によると

A blazing fast JSON parser and generator in pure Elixir.

とのことでJsonパーサーとジェネレーターのようです。

Json形式の文字列を理解しやすいように加工してくれるようです。

mix.exsに対して
{:json, "~> 1.4"}を追加、mix deps.getで依存関係の取得を行います。

iex(2)> %{"first" => 1, "last" => 10, "step" => 2}
%{"first" => 1, "last" => 10, "step" => 2}
iex(3)> |> Jason.encode!
"{\"first\":1,\"last\":10,\"step\":2}"
iex(4)> |> Jason.decode!(keys: :atoms)
%{first: 1, last: 10, step: 2}
iex(5)> %{first: 1, last: 10, step: 2}
%{first: 1, last: 10, step: 2}
iex(6)> |> Jason.encode!
"{\"first\":1,\"last\":10,\"step\":2}"
iex(7)> |> Jason.decode!
%{"first" => 1, "last" => 10, "step" => 2}

エンコードデコードが簡単にできます。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?