Skip to content

Commit

Permalink
Handling pretty: false (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheharyarn authored and michalmuskala committed Oct 19, 2018
1 parent 5941f26 commit ba318c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jason.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ defmodule Jason do
end
end

defp do_encode(input, %{pretty: pretty} = opts) do
defp do_encode(input, %{pretty: pretty} = opts) when pretty !== false do
case Encode.encode(input, opts) do
{:ok, encoded} -> {:ok, Formatter.pretty_print_to_iodata(encoded, pretty)}
other -> other
Expand Down
4 changes: 4 additions & 0 deletions test/encode_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ defmodule Jason.EncoderTest do
assert to_json(%{a: 3.14159, b: 1}, pretty: true) == ~s|{\n "a": 3.14159,\n "b": 1\n}|
end

test "pretty: false" do
assert to_json(%{a: 3.14159, b: 1}, pretty: false) == ~s|{"a":3.14159,"b":1}|
end

defp to_json(value, opts \\ []) do
Jason.encode!(value, opts)
end
Expand Down

0 comments on commit ba318c8

Please sign in to comment.