Created
March 30, 2012 22:02
-
-
Save btoone/2255909 to your computer and use it in GitHub Desktop.
Parse JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
json = '{ | |
"description":"the description for this gist", | |
"public":true, | |
"files":{ | |
"file1.txt":{ | |
"content":"String file contents" | |
} | |
} | |
}' | |
hash = { | |
"description" => "the description for this gist", | |
"public" => true, | |
"files" => { | |
"file1.txt" => { | |
"content" => "String file contents" | |
} | |
} | |
} | |
h = JSON.parse(json) | |
p h.class | |
p h | |
p h['description'] | |
puts "" | |
j = JSON.generate(hash) | |
p j.class | |
p j | |
puts j |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment