Skip to content

Instantly share code, notes, and snippets.

@frangucc
Created January 26, 2011 19:56
Show Gist options
  • Select an option

  • Save frangucc/797321 to your computer and use it in GitHub Desktop.

Select an option

Save frangucc/797321 to your computer and use it in GitHub Desktop.
Parse nested JSON with JSON
require 'rubygems'
require 'json'
json_str = '[
{"title":"GRE Connect","subject":"GRE","type":["bookmark"]},
{"title":"GRE Connect","desc":"another book","type":["bookmark","bookmark_type","reading"]}
]'
arr = JSON.parse(json_str)
p arr
puts
target_hash = arr[1]
target_hash.each do |key, val|
if key == 't'
val.each {|elmt| puts elmt}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment