iij/mruby-iijson — pull request #5 by psuhh (2014-06-06 18:54:52+00:00)
Title: Add support generating pretty printed json

Use `JSON.generate(json, {:pretty_print => true, :indent_with => "\t"})` to generate pretty printed json indented with tab character.

Default options are `{:pretty_print => false, :indent_with => 2}` (`:indent_with` can be both string and Fixnum, where Fixnum specifies how many spaces are used).

Example:
```ruby
test = {
"Image" => {
"Width" => 800,
"Height" => 600,
"Title" => "View from 15th Floor",
"Thumbnail" => {
"Url" => "http://www.example.com/image/481989943",
"Height" => 125,
"Width" => "100"
},
"IDs" => [116, 943, 234, 38793]
}
}

puts JSON.generate(test)
puts JSON.generate(test, {:pretty_print => true, :indent_with => 2})

# Output
# {"Image":{"Width":800,"Height":600,"Title":"View from 15th Floor","Thumbnail":{"Url":"http://www.example.com/image/481989943","Height":125,"Width":"100"},"IDs":[116,943,234,38793]}}
# {
# "Image": {
# "Width": 800,
# "Height": 600,
# "Title": "View from 15th Floor",
# "Thumbnail": {
# "Url": "http://www.example.com/image/481989943",
# "Height": 125,
# "Width": "100"
# },
# "IDs": [
# 116,
# 943,
# 234,
# 38793
# ]
# }
# }
```