JSON-JRuby is a Java port of Florian Frank's json library. It provides fast JSON generation and parsing for JRuby.
Just install the gem under JRuby:
$ jruby -S gem install json-jruby
Basic usage is quite straightforward:
#! /usr/bin/env jruby
require "rubygems"
require "json"
# de-serializing:
source_string = '{"sample": "Hello, world!"}'
puts JSON(source_string).inspect
# => {"sample"=>"Hello, world!"}
# serializing:
source_object = ["Just another Ruby Array", {"null value" => nil}]
puts JSON(source_object)
# => ["Just another Ruby Array",{"null value":null}]
For detailed usage and configuration parameters, see the json gem documentation.
Check the project page for information regarding file downloads. To pull the Git repository:
$ git clone git://github.com/mernen/json-jruby.git
The JDK version 1.5 or 1.6, JRuby 1.1 and Ragel 6.0 are needed to build this package.
After downloading a source package, you may need to configure the jruby.dir setting in nbproject/project.properties (defaults to ../jruby). Ragel just needs to be in your path. Then, from the source's directory, you may run ant to build a gemfile.
jsonjson will only accept Hashes, whereas json-jruby would accept anything that responds to to_hash.For regular use, though, there are no practical differences between the libraries.
This library has been written and is maintained by Daniel Luz, a.k.a. mernen, based on Florian Frank's work.
JSON-JRuby, like json, is distributed under the Ruby license.