Skip to content

Commit ba318c8

Browse files
sheharyarnmichalmuskala
authored andcommitted
Handling pretty: false (michalmuskala#58)
1 parent 5941f26 commit ba318c8

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/jason.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ defmodule Jason do
207207
end
208208
end
209209

210-
defp do_encode(input, %{pretty: pretty} = opts) do
210+
defp do_encode(input, %{pretty: pretty} = opts) when pretty !== false do
211211
case Encode.encode(input, opts) do
212212
{:ok, encoded} -> {:ok, Formatter.pretty_print_to_iodata(encoded, pretty)}
213213
other -> other

test/encode_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ defmodule Jason.EncoderTest do
155155
assert to_json(%{a: 3.14159, b: 1}, pretty: true) == ~s|{\n "a": 3.14159,\n "b": 1\n}|
156156
end
157157

158+
test "pretty: false" do
159+
assert to_json(%{a: 3.14159, b: 1}, pretty: false) == ~s|{"a":3.14159,"b":1}|
160+
end
161+
158162
defp to_json(value, opts \\ []) do
159163
Jason.encode!(value, opts)
160164
end

0 commit comments

Comments
 (0)