Skip to content

Instantly share code, notes, and snippets.

@mverzilli
Last active September 16, 2016 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mverzilli/40875d5351a83f1dfbac442b5a7eaca6 to your computer and use it in GitHub Desktop.
Save mverzilli/40875d5351a83f1dfbac442b5a7eaca6 to your computer and use it in GitHub Desktop.
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