Skip to content

Instantly share code, notes, and snippets.

@mverzilli
Last active Sep 16, 2016
Embed
What would you like to do?
piedoom's problem
require "json"
class Blog
JSON.mapping({
name: {type: String},
likes: {type: Int32},
following: {type: Int32},
default_post_format: {type: String},
})
end
json_string = %({
"response": {
"user": {
"name": "doomy",
"likes": 37358,
"following": 205,
"default_post_format": "html"}
}})
pull = JSON::PullParser.new(json_string)
blog = pull.on_key!("response") do
pull.on_key!("user") do
Blog.new(pull)
end
end
pp blog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment