Skip to content

Commit

Permalink
JSON::ArrayBuilder#push_raw method
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya authored and asterite committed Dec 27, 2016
1 parent 48af685 commit 2de5577
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec/std/json/serialization_spec.cr
Expand Up @@ -300,11 +300,12 @@ describe "JSON serialization" do
io.json_array do |array2|
array2 << 2
array2 << 3
array2.push_raw(%Q<{"d":"e"}>)
end
end
end
end
result.should eq("[1,[2,3]]")
result.should eq(%q<[1,[2,3,{"d":"e"}]]>)
end

it "generate object with raw_field" do
Expand Down
5 changes: 5 additions & 0 deletions src/json/to_json.cr
Expand Up @@ -64,6 +64,11 @@ struct JSON::ArrayBuilder(T)
push { value.to_json(@io) }
end

# Appends a JSON raw value into this array
def push_raw(value)
push { value.to_s(@io) }
end

# Executes the block, expecting it to append a value
# in this array
def push
Expand Down

0 comments on commit 2de5577

Please sign in to comment.