avsej / gson.rb

Ruby wrapper for google-gson library
Apache License 2.0
10 stars 5 forks source link

gson.rb

Ruby wrapper for google-gson library

Build Status

Installation

Add this line to your application's Gemfile:

gem 'gson'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gson

Usage

Encoding

Gson::Encoder.new.encode({"abc" => [123, -456.789]})
=> "{\"abc\":[123,-456.789]}"

Gson::Decoder#decode also accept optional IO or StringIO object:

File.open("/tmp/gson.json", "w+") do |io|
  Gson::Encoder.new.encode({"foo" => "bar"}, io)
end
File.read("/tmp/gson.json")
=> "{\"foo\":\"bar\"}"

Additional encoder options:

Decoding

Gson::Decoder.new.decode('{"abc":[123,-456.789e0]}')
=> {"abc"=>[123, -456.789]}

Gson::Decoder#decode also accept IO or StringIO objects:

Gson::Decoder.new.decode(File.open("valid-object-single.json"))
=> {"a"=>"b"}

Additional decoder options:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request