Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/json_on_steroids_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module JsonOnSteriodsSpec
describe JSON::OnSteroids do
describe "#to_json" do
it "should support returning a String" do
(JSON::OnSteroids.new a: 1, b: 2).to_json.should eq %<{"a":1,"b":2}>
end

it "should support writing to IO" do
output = String.build do |str|
(JSON::OnSteroids.new a: 1, b: 2).to_json(str)
end
output.should eq %<{"a":1,"b":2}>
end
end
end
end
4 changes: 4 additions & 0 deletions src/json_on_steroids.cr
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ class JSON::OnSteroids
to_s
end

def to_json(io : IO) : Nil
to_s(io)
end

def inspect(io)
io << "JSON::OnSteroids(dirty: #{dirty?.inspect})>" unless @parent

Expand Down