Skip to content

Instantly share code, notes, and snippets.

@coderek
Last active December 24, 2015 06:39
Show Gist options
  • Save coderek/6758981 to your computer and use it in GitHub Desktop.
Save coderek/6758981 to your computer and use it in GitHub Desktop.
jruby -S gem install json-jruby
## install json-jruby library
# jruby -S gem install json-jruby
## create json.rb file which contains code below
## generate json.class file
# jrubyc json.rb
## run
# java -cp .:/path/to/jruby-complete-1.7.4.jar json
## should see some output
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}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment