iij/mruby-iijson — pull request #3 by psuhh (2014-06-06 18:04:44+00:00)
Title: Add pretty printing option and fix segfault on parsing empty strings

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).

`JSON.generate("")` used to cause segfault. Now returns `mrb_nil_value()`

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
# ]
# }
# }
```