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
2 changes: 1 addition & 1 deletion lib/psych.rb
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def self.dump_stream *objects
def self.to_json object
visitor = Psych::Visitors::JSONTree.create
visitor << object
visitor.tree.yaml
visitor.tree.yaml(nil, line_width: -1)
end

###
Expand Down
10 changes: 10 additions & 0 deletions test/psych/test_json_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def test_string
assert_match(/"foo"/, Psych.to_json("foo"))
end

def test_long_string
string = 'word ' * 30
assert_equal "\"#{string}\"\n", Psych.to_json(string)
end

def test_long_string_in_sequence
string = 'word ' * 30
assert_include Psych.to_json([[1, string]]), "\"#{string}\""
end

def test_symbol
assert_match(/"foo"/, Psych.to_json(:foo))
end
Expand Down