Skip to content

Instantly share code, notes, and snippets.

@prcongithub
Created September 26, 2013 09:10
Show Gist options
  • Save prcongithub/6711727 to your computer and use it in GitHub Desktop.
Save prcongithub/6711727 to your computer and use it in GitHub Desktop.
hash to json
hash = {
:persons => []
}
persons.each do |person|
person_hash = {
:name => person.name,
:email => person.email,
:phone => []
}
person.phone_numbers.each do |number|
person_hash[:phone] << number
end
hash[:persons] << person_hash
end
hash.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment