diff options
Diffstat (limited to 'lib/json/pure/generator.rb')
-rw-r--r-- | lib/json/pure/generator.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index 9056a5d..1419074 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -363,7 +363,11 @@ module JSON result << state.space_before result << ':' result << state.space - result << value.to_json(state) + if value.respond_to?(:to_json) + result << value.to_json(state) + else + result << %{"#{String(value)}"} + end first = false } depth = state.depth -= 1 @@ -398,7 +402,11 @@ module JSON each { |value| result << delim unless first result << state.indent * depth if indent - result << value.to_json(state) + if value.respond_to?(:to_json) + result << value.to_json(state) + else + result << %{"#{String(value)}"} + end first = false } depth = state.depth -= 1 |