Skip to content

Commit af4ae70

Browse files
authored
Merge pull request #197 from RudolfMan/rm-poison
2 parents af0f395 + 4495364 commit af4ae70

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/poison.ex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ defmodule Poison do
2424
{:error, exception}
2525
end
2626

27+
@doc """
28+
Encode a value to JSON as iodata.
29+
30+
iex> Poison.encode_to_iodata([1, 2, 3])
31+
{:ok, [91, ["1", 44, "2", 44, "3"], 93]}
32+
"""
33+
@spec encode_to_iodata(Encoder.t, Keyword.t) :: {:ok, iodata} | {:error, {:invalid, any}}
34+
def encode_to_iodata(value, options \\ []) do
35+
encode(value, [iodata: true] ++ options)
36+
end
37+
2738
@doc """
2839
Encode a value to JSON, raises an exception on error.
2940
@@ -45,6 +56,17 @@ defmodule Poison do
4556
end
4657
end
4758

59+
@doc """
60+
Encode a value to JSON as iodata, raises an exception on error.
61+
62+
iex> Poison.encode_to_iodata!([1, 2, 3])
63+
[91, ["1", 44, "2", 44, "3"], 93]
64+
"""
65+
@spec encode_to_iodata!(Encoder.t, Keyword.t) :: iodata | no_return
66+
def encode_to_iodata!(value, options \\ []) do
67+
encode!(value, [iodata: true] ++ options)
68+
end
69+
4870
@doc """
4971
Decode JSON to a value.
5072

0 commit comments

Comments
 (0)